In Qt, all GUI updates have to occur in the main thread. You can't implement drawing operations in a different thread. You also can't do anything in a paint event which will trigger another paint event (like call update or resize the widget, etc.). And finally, paint event handling is optimized to eliminate unnecessary repainting. If nothing has changed to require repainting, or if there are several paint events in the event queue, only the last one will be executed and the rest discarded.
All on-screen QWidget painting is event driven, and you can only create a QPainter and draw during a paintEvent().
In any case, this is the wrong way to go about it. If you want something to happen at given intervals, you implement a QTimer, and connect a slot to the QTimer::timeout() signal. In the slot, make the changes you want, then call update() (or if you have changed a widget property that triggers an update, like resizing, the widget will probably repaint itself).
Finally, if you construct your QPainter instance with "self" as the argument, you do not need to call QPainter::begin() / QPainter::end(). When you use this constructor (qp = QPainter( self )), it calls begin() inside the constructor, and end() when it is destroyed when the paintEvent() exits.
Bookmarks