During a paint event, How can I reuse previous paintings so that I can just paint on top of the previous result. Right now the whole rendering area needs repainting.
gonna try QPixmap.
Do I absolutely need to use update?
During a paint event, How can I reuse previous paintings so that I can just paint on top of the previous result. Right now the whole rendering area needs repainting.
gonna try QPixmap.
Do I absolutely need to use update?
If you want to avoid instantiating variables in the paintEvent() you could make them member variables - this includes the QPainter object. You only need to call update() when you need the widget to repaint itself.
Why do you not want to just repaint it from scratch? Is this some kind of premature optimization, or have you noticed slow-down?
You want to cache the painting in a QImage
or QPixmap
(probably a QPixmap
). If you do this a lot, you might also want to look at QPixmapCache
.
Additionally, a lot of drawing can be calculated beforehand, then fairly quickly done using QPainterPath
s. I will often use them and recalculate when necessary, rather than caching the whole paint event in a pixmap.
Edit:
I also ran into a brief mention of QPicture, which might also be something you want to look at:
The QPicture class is a paint device that records and replays QPainter commands.