QPainter 使用注意事项

来源:互联网 发布:fastqc数据质控报告 编辑:程序博客网 时间:2024/05/03 14:39
QPainter 使用注意事项

最近创建了一个继承 QWidget 的窗口部件,使用 QPainter 绘制需要的内容,一部分在 paintEvent 中使用 QPainter,另一部分在自定义函数中使用 QPainter,发现运行时警告:
QWidget::paintEngine: Should no longer be called kernel……
QPainter::begin: Paint device returned engine == 0, type: 1 painting……

查找 QPainter 文档,发现如下事项:
Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent().

这才明白,QPainter 默认只能在 paintEvent 里面调用,在别处绘制就会遇到警告。另外,在构造函数中设置属性:

this->setAttribute(Qt::WA_PaintOutsidePaintEvent); 

是可以在paintEvent()之外绘制;
但不幸的是,该属性只支持X11,对于 Windows、Mac OS X、Embedded Linux 均不予支持。
0 0
原创粉丝点击