Qt问题
以下代码的区别是什么Qt问题,qt,qt4,colors,symbian,brush,Qt,Qt4,Colors,Symbian,Brush,以下代码的区别是什么 QGraphicsScene * scence = new QGraphicsScene(); QBrush *brush = new QBrush((QColor(60,20,20))); scence->setBackgroundBrush(*brush); QGraphicsView *view = new QGraphicsView(); view->setScene(scence); //view->setB
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文档所说: 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();
希望有帮助 实现相同结果的另一种方法是将颜色放入笔刷构造函数中,并应用默认的实体样式:
QBrush *brush = new QBrush (QColor (60, 20, 20));
采用颜色的构造函数具有样式的可选参数,默认为Qt::SolidPattern。这两种方法都产生相同的结果,但这一种使用更少的两行代码