Results 1 to 5 of 5

Thread: QPainter save - restore ... Sincerely I dont know

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QPainter save - restore ... Sincerely I dont know

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPainter save - restore ... Sincerely I dont know

    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.
    Qt Code:
    1. p.save(); // = save point 1
    2. // do fancy stuff with p
    3. p.save(); // = save point 2
    4. // do fancy stuff with p
    5. p.restore(); // now p is like save point 2
    6. // do fancy stuff with p
    7. p.restore(); // now p is like save point 1
    To copy to clipboard, switch view to plain text mode 

  3. The following 2 users say thank you to Lykurg for this useful post:

    saa7_go (6th October 2010), tonnot (5th October 2010)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QPainter save - restore ... Sincerely I dont know

    It works for non-fancy stuff too
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #4
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainter save - restore ... Sincerely I dont know

    Thanks Lykurg, now I understand it

  6. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: QPainter save - restore ... Sincerely I dont know

    Quote Originally Posted by wysota View Post
    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.

Similar Threads

  1. Save and restore QByteArray in mysql database
    By ruben.rodrigues in forum Newbie
    Replies: 0
    Last Post: 9th August 2010, 09:43
  2. QGraphicsView dont refresh
    By ProTonS in forum Qt Programming
    Replies: 2
    Last Post: 11th September 2009, 14:05
  3. Save & Restore a selection in QTreeWidget
    By youkai in forum Qt Programming
    Replies: 1
    Last Post: 1st September 2008, 19:54
  4. QPainter save() and restore()
    By babu198649 in forum Newbie
    Replies: 4
    Last Post: 28th July 2008, 09:22
  5. QPainter::save and QPAinter::restore()
    By quickNitin in forum Newbie
    Replies: 2
    Last Post: 17th June 2006, 22:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.