Results 1 to 5 of 5

Thread: QPainter save() and restore()

  1. #1
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default QPainter save() and restore()

    hi
    i am doing only one operation inside paintEvent(QPainter::drawPixmap()) ,is it necessary to use save() and restore() .

  2. #2
    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() and restore()

    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.

  3. The following user says thank you to wysota for this useful post:

    babu198649 (28th July 2008)

  4. #3
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: QPainter save() and restore()

    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().

  5. #4
    Join Date
    Jan 2008
    Location
    Finland /Pakistan
    Posts
    216
    Thanks
    20
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QPainter save() and restore()

    If you perform one operation at a time and require the same operation sometime later then save it and restore it later ...

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QPainter save() and restore()

    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 what are saved and restored.
    J-P Nurmi

  7. The following user says thank you to jpn for this useful post:

    babu198649 (28th July 2008)

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.