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
.
精彩评论