Qt绘制矩形在后台
Qt drawRect in background
我想绘制一个滑块的背景。我试过这个,但是颜色覆盖了整个滑块。这是在QSlider
的继承类中void paintEvent(QPaintEvent *e) {
QPainter painter(this);
painter.begin(this);
painter.setBrush(/*not important*/);
// This covers up the control. How do I make it so the color is in
// the background and the control is still visible?
painter.drawRect(rect());
painter.end();
}
要设置小部件的背景,可以设置样式表:
theSlider->setStyleSheet("QSlider { background-color: green; }");
下面的代码将设置小部件的背景,允许您做更多的事情:
void paintEvent(QPaintEvent *event) {
QPainter painter;
painter.begin(this);
painter.fillRect(rect(), /* brush, brush style or color */);
painter.end();
// This is very important if you don't want to handle _every_
// detail about painting this particular widget. Without this
// the control would just be red, if that was the brush used,
// for instance.
QSlider::paintEvent(event);
}
,顺便说一句。下面两行示例代码将产生一个警告:
QPainter painter(this);
painter.begin(this);
也就是使用GCC的这个:
QPainter::begin:一个油漆装置只能由一个画家在一段时间。
所以要确保,就像我在例子中做的那样,你要么做QPainter painter(this)
要么做painter.begin(this)
相关文章:
- QuadTree只在窗口的右上角绘制
- 绘制旋转的三角形
- flutter:即使shouldRepaint()返回true,自定义画家也不会重新绘制
- 如何在QT中的自定义视频小工具t上绘制矩形
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 无法使用VAO和EBO(openGL)绘制多个对象
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- 绘制顺时针三角形,重新排序点
- 在顶点着色器中使用 OpenGl 的未声明标识符,我在顶点着色器中绘制三角形时遇到问题
- SFML 文本未绘制在窗口上
- 如何在快板的屏幕中显示子位图的绘制?
- 如何绘制自定义形状的元素?
- QPainter 将 QBrush 设置为 在 QT/C++ 中绘制文本
- 除非重新绘制大小,否则SDL_Texture在调整大小后呈现黑色
- 绘制文本问题
- 在 QT C++中绘制/操作多边形
- 如何在 Gnuplot 中分别绘制 2 个文件数据?我有一个文件"sin.txt",另一个文件"cos.txt",我想将它们分别绘制在一个图表上
- 在现代OpenGL中,绘制GL_TRIANGLE奇怪的z轴行为的填充圆
- OpenGL 着色器不绘制任何东西 - 糟糕的精灵类
- Qt绘制矩形在后台