tags:

views:

50

answers:

2

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?

+1  A: 

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?

JimDaniel
Havent noticed a slowdown, doing it for optimization.
yan bellavance
after completing my paintEvent I see that it is less complicated to just repaint the whole thing everytime
yan bellavance
+1  A: 

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 QPainterPaths. 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.

Caleb Huitt - cjhuitt
Make sure that you use the integer based interface of the pixmap cache and not the old string based one (added in 4.6).
e8johan