Results 1 to 5 of 5

Thread: update and paintevent

  1. #1
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Cool update and paintevent

    hi ,
    function update() is used to paint all the area, and update(const QRegion & rgn) is used to paint rgn area. After calling the update() or update(const QRegion & rgn), function paintEvent will be called. I have a doubt about that, no matter I call the function update() or the function update(const QRegion & rgn), function paintevent will be called, and then my program will paint all area (because function paintEvent will paint all area).

    so i think update() has no different with update(const QRegion & rgn). Is that right?
    I want to know the reason .

    I'm sorry about my poor english, but I really want to know the answer.

    thanks very mush

  2. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: update and paintevent

    Yes, in your case update() and update(QRegion) will behave the same as your painEvent() will redraw every thing. In a case where the widget has complex painting, and repainting all the widget is very costly, there update(QRegion) is used. For complex / slow painting widgets while imlementing paintEvent() only QPaintEvent::region() has to painted instead of all the widget.

    Quote Originally Posted by Qt Docs
    Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QTableView do this, for example

    Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::united()). The repaint() function does not permit this optimization, so we suggest using update() whenever possible.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  3. #3
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: update and paintevent

    thank you for the answer.
    you mean that I need paint the region which returned by QPaintEvent::region() in my function paintEvent() myself ? Or QT does it?

  4. #4
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: update and paintevent

    you mean that I need paint the region which returned by QPaintEvent::region() in my function paintEvent() myself ? Or QT does it?
    Qt only determines which section of widget (i.e. QPaintEvent::region()) has to be re-painted, You need paint it yourself in paintEvent(). Note that it is not mandatory to do so, but will be useful in case where painting whole widget is slow.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  5. #5
    Join Date
    Apr 2012
    Posts
    17
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: update and paintevent

    thank you. I understand.

    I thought too much.

Similar Threads

  1. Newbie-Question: update does not trigger paintEvent
    By janitor in forum Qt Programming
    Replies: 5
    Last Post: 24th January 2013, 17:59
  2. Replies: 4
    Last Post: 10th June 2010, 21:25
  3. Replies: 0
    Last Post: 29th April 2010, 05:44
  4. Paintevent and update
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 25th March 2008, 07:09
  5. Calling update() from paintEvent()
    By wonder.mice in forum Qt Programming
    Replies: 8
    Last Post: 11th January 2008, 13:41

Tags for this Thread

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.