PDA

View Full Version : QPainter save - restore ... Sincerely I dont know



tonnot
5th October 2010, 16:56
Save() Saves the current painter state (pushes the state onto a stack). A save() must be followed by a corresponding restore();
Restore :Restores the current painter state (pops a saved state off the stack).
At analogclock example code I see that it is used after setpen & setbrush. I understand the restore function (clear the set's ?) but save ?
Any easy explanation ?

Lykurg
5th October 2010, 17:06
Obviously you don't understand the restore function. It doesn't clear the sets. It restores the settings as they were when save() was called.

QPainter p;
p.save(); // = save point 1
// do fancy stuff with p
p.save(); // = save point 2
// do fancy stuff with p
p.restore(); // now p is like save point 2
// do fancy stuff with p
p.restore(); // now p is like save point 1

wysota
5th October 2010, 17:07
It works for non-fancy stuff too ;)

tonnot
5th October 2010, 17:34
Thanks Lykurg, now I understand it

Lykurg
5th October 2010, 22:47
It works for non-fancy stuff too ;)
Indeed, after I spend several hours on intense testing, I can affirm it too. I would have never dreamed of that, it's amazing! Qt is so simple but powerful.