Results 1 to 4 of 4

Thread: Use of repaint/update

  1. #1
    Join Date
    Sep 2006
    Posts
    23
    Thanks
    8
    Qt products
    Qt3 Qt4

    Default Use of repaint/update

    Hi everybody,

    my old qt3 application had to draw on a qmainwindow outside the paintevent. It happened outside the main loop as well. Now everything changes.

    Are QWidget::updates() and QWidget::repaint() valid only inside the main loop ?

    I the repaint() heavier and slower than update() ?

    Thank you for your attention !

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Use of repaint/update

    Quote Originally Posted by Placido Currò View Post
    my old qt3 application had to draw on a qmainwindow outside the paintevent.
    You can set Qt::WA_PaintOutsidePaintEvent widget attribute, but it works only under X11.

    Quote Originally Posted by Placido Currò View Post
    Are QWidget::updates() and QWidget::repaint() valid only inside the main loop ?
    What does "inside the main loop" exactly mean? Do you use threads?

    Quote Originally Posted by Placido Currò View Post
    I the repaint() heavier and slower than update() ?
    update() just posts an event, which will be processed by the event loop, repaint() repaints the widget immediately.

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Use of repaint/update

    my old qt3 application had to draw on a qmainwindow outside the paintevent.
    This is not possible in Qt4.
    In Qt4 all drawing must take place in the paintEvent().
    Are QWidget::updates() and QWidget::repaint() valid only inside the main loop ?
    Yes.
    I the repaint() heavier and slower than update() ?
    The difference is not of that kind since painting is only done in paintEvent().
    The difference is in the way paintEvent() is called as a result.
    repaint() calles paintEvent() immidiently, where as update() posts an event in a way that allows Qt to schedule it in the best way (optimized).

    Beat to it by Jacek

  4. The following user says thank you to high_flyer for this useful post:

    Placido Currò (10th April 2007)

  5. #4
    Join Date
    Aug 2006
    Posts
    44
    Thanked 7 Times in 7 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Use of repaint/update

    Quote Originally Posted by Placido Currò View Post
    Is the repaint() heavier and slower than update() ?!
    That depends. By using update(), the paint system can 'accumulate' a region that needs repainting and thus optimize painting somewhat. There is overhead invovled in setting up to paint in the acquisition and release of system resources.

    If you're calling repaint() a lot and always redrawing the entire window, you could drag performance down a lot.

    Basically, try to avoid repaint() in a tight loop. Ideally, you should get something 'good enough' using regular update() calls (with a region, of course).

    And as the others have posted, repaint() immediately sends a paintEvent() rather than accumulating an invalidated region until the system is ready for you to paint, so it may incur more overhead when done often.

  6. The following user says thank you to Eldritch for this useful post:

    Placido Currò (10th April 2007)

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.