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
.