QPainter begin Paint device returned engine

QPainter::begin: Paint device returned engine == 0, type: 1
QPainter默认只能在paintEvent里面调用,但是:

在其他事件中绘制窗体,提示信息如下:

1
QPainter::begin: Paint device returned engine == 0, type: 1

绘制操作应该在paintEvent中完成.

有一个属性值,在构造函数中设置可以在paintEvent()之外进行绘制:

1
this->setAttribute(Qt::WA_PaintOutsidePaintEvent);

但是只支持X11,对于 Windows, Mac OS X or Embedded Linux。。。。不予支持

1
2
3
4
5
6
7
void xx::paintEvent(QPaintEvent *p)

painter.begin(this);

painter.drawImage(image);

painter.end();