【问题标题】:Qt Qbrush issueQt Qbrush 问题
【发布时间】:2011-01-24 22:46:21
【问题描述】:

下面的代码有什么区别,

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

它什么也没给。

【问题讨论】:

    标签: qt qt4 colors symbian brush


    【解决方案1】:

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

    希望对你有帮助!

    【讨论】:

      【解决方案2】:

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

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

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

      【讨论】:

        猜你喜欢
        • 2015-10-17
        • 2017-05-31
        • 2011-09-20
        • 1970-01-01
        • 1970-01-01
        • 2011-05-28
        • 2020-06-23
        • 2018-08-11
        • 2010-10-14
        相关资源
        最近更新 更多