PDA

View Full Version : Use of repaint/update



Placido Currò
2nd April 2007, 09:53
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 !

jacek
2nd April 2007, 10:53
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.


Are QWidget::updates() and QWidget::repaint() valid only inside the main loop ?
What does "inside the main loop" exactly mean? Do you use threads?


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.

high_flyer
2nd April 2007, 10:54
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 :)

Eldritch
3rd April 2007, 19:24
Is the repaint() heavier and slower than update() ?!

That depends. :D 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.