Qt Qbrush问题

发布于 2024-08-24 02:04:27 字数 832 浏览 3 评论 0原文

以下代码有什么区别,

  QGraphicsScene * scence = new QGraphicsScene();

   QBrush *brush = new QBrush((QColor(60,20,20)));
   scence->setBackgroundBrush(*brush);

   QGraphicsView *view = new QGraphicsView();
   view->setScene(scence);
   //view->setBackgroundBrush(*brush);
   //view->setCacheMode(QGraphicsView::CacheBackground);
   view->showFullScreen();

给出黑色背景,

  QGraphicsScene * scence = new QGraphicsScene();

   QBrush *brush = new QBrush();
   brush->setColor(QColor(60,20,20));
   scence->setBackgroundBrush(*brush);

   QGraphicsView *view = new QGraphicsView();
   view->setScene(scence);
   //view->setBackgroundBrush(*brush);
   //view->setCacheMode(QGraphicsView::CacheBackground);
   view->showFullScreen();

但什么也没有给出。

What is the difference in the following code,

  QGraphicsScene * scence = new QGraphicsScene();

   QBrush *brush = new QBrush((QColor(60,20,20)));
   scence->setBackgroundBrush(*brush);

   QGraphicsView *view = new QGraphicsView();
   view->setScene(scence);
   //view->setBackgroundBrush(*brush);
   //view->setCacheMode(QGraphicsView::CacheBackground);
   view->showFullScreen();

gives black color background

  QGraphicsScene * scence = new QGraphicsScene();

   QBrush *brush = new QBrush();
   brush->setColor(QColor(60,20,20));
   scence->setBackgroundBrush(*brush);

   QGraphicsView *view = new QGraphicsView();
   view->setScene(scence);
   //view->setBackgroundBrush(*brush);
   //view->setCacheMode(QGraphicsView::CacheBackground);
   view->showFullScreen();

it gives nothing.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲性难收 2024-08-31 02:04:27

正如 Qt 文档所说:

QBrush::QBrush ()
构造一个样式为 Qt::NoBrush 的默认黑色画笔(即该画笔不会填充形状)。

在第二个示例中,您必须通过 setStyle 设置 QBrush 对象的样式(),例如使用 Qt::SolidPattern

   QGraphicsScene * scence = new QGraphicsScene();
   QBrush *brush = new QBrush();
   brush->setStyle(Qt::SolidPattern); // Fix your problem !
   brush->setColor(QColor(60,20,20));
   scence->setBackgroundBrush(*brush);

   QGraphicsView *view = new QGraphicsView();
   view->setScene(scence);
   //view->setBackgroundBrush(*brush);
   //view->setCacheMode(QGraphicsView::CacheBackground);
   view->showFullScreen();

希望有帮助!

As the Qt doc says :

QBrush::QBrush ()
Constructs a default black brush with the style Qt::NoBrush (i.e. this brush will not fill shapes).

In your second example, you have to set the style of the QBrush object by setStyle(), for example with Qt::SolidPattern.

   QGraphicsScene * scence = new QGraphicsScene();
   QBrush *brush = new QBrush();
   brush->setStyle(Qt::SolidPattern); // Fix your problem !
   brush->setColor(QColor(60,20,20));
   scence->setBackgroundBrush(*brush);

   QGraphicsView *view = new QGraphicsView();
   view->setScene(scence);
   //view->setBackgroundBrush(*brush);
   //view->setCacheMode(QGraphicsView::CacheBackground);
   view->showFullScreen();

Hope it helps !

憧憬巴黎街头的黎明 2024-08-31 02:04:27

实现相同结果的另一种方法是将颜色放入画笔构造函数中,并应用默认的实体样式:

 QBrush *brush = new QBrush (QColor (60, 20, 20));

采用颜色的构造函数有一个可选的样式参数,默认为 Qt::SolidPattern。两种方法产生相同的结果,但这种方法少用了两行代码。

An alternate approach that achieves the same result is to put the color in the brush constructor, and that applies a default style of solid:

 QBrush *brush = new QBrush (QColor (60, 20, 20));

The constructors that take a color have an optional parameter for the style, which defaults to Qt::SolidPattern. Both approaches produce the same result, but this one uses two fewer lines of code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文