Qt Qbrush Question

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 background color

  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();

gives nothing.

+3
source share
2 answers

As the Qt doc reports:

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

In your second example, you must set the style of the QBrush object using setStyle (), for example, using 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 this helps!

+7
source

, , , :

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

, , , Qt:: SolidPattern. , .

0

Source: https://habr.com/ru/post/1735908/


All Articles