Qt Qbrush 问题

标签 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->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/

相关文章:

javascript - 如何在不使用 QML 函数的情况下根据 QQuickItem 的当前值转换其 x 或 y 属性

qt - QT中QVariantMap Json解析

c++ - 使用 updatePaintNode : new frame only appears when I resize screen 在 QT/OpenGL 中渲染视频

c++ - 在 MSVC2010 Express 和 Qt 4.8 (Qt Creator 2.4.1) 中调试资源文件编译 (rc.exe)

c++ - Qt : Display byte from QByteArray

c# - 如何从图像生成突出颜色的调色板?

java - 按位除法? (改变整数的格式)

visual-studio-2008 - Resharper 4.5 打破了我的配色方案

c++ - 如何在特定行中打印 QString

windows - 包含 <windows.h> 时出现 Qt 错误