PDA

View Full Version : QPainter save() and restore()



babu198649
27th July 2008, 11:40
hi
i am doing only one operation inside paintEvent(QPainter::drawPixmap()) ,is it necessary to use save() and restore() .

wysota
27th July 2008, 11:55
No, of course not, Qt guards the painter state itself before calling your code, so all the changes to the painter will be restored after the paint event of yours is left.

babu198649
28th July 2008, 08:17
If i do a series of operations inside a paintEvent(pixmap painting,draw lines,e.t.c),then is it necessary to use save() and restore().

salmanmanekia
28th July 2008, 08:36
If you perform one operation at a time and require the same operation sometime later then save it and restore it later ...:)

jpn
28th July 2008, 09:22
You will instantiate a different QPainter object on the stack during every paintEvent() anyway so saving and restoring doesn't make sense unless you really need to get back to some earlier state. Drawing a line doesn't change the state of a QPainter object, but for example setting a pen before drawing the line does. QPainter docs contain a list of settings (http://doc.trolltech.com/4.4/qpainter.html#settings) what are saved and restored.