下面的代码有什么区别,
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();
希望对你有帮助!
关于Qt Qbrush 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2400936/