开发者

Draw with QPainter

I need draw with QPainter, but when I try to do it not in

void paintEvent( QPaintEvent* )

I catch error:

QPainter::setPen: Painter not active

QPainter::setBrush: Painter not active

Can I use QPainter not in void paintEvent( QPaintEvent* ) ?

开发者_如何学编程

Thank you.


You are using a widget as the paint device for QPainter. In this case, QPainter can usually only be used within the context of the widget's paint event. The QPainter documentation has the following to say about this:

Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt::WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.

It is possible to use QPainter outside a paint event by setting another paint device for QPainter, for example a QPixmap.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜