PDA

View Full Version : update and paintevent



yuzhouzhiwai
15th July 2013, 12:34
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

Santosh Reddy
15th July 2013, 13:13
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.


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.

yuzhouzhiwai
15th July 2013, 14:15
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?

Santosh Reddy
15th July 2013, 14:25
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.

yuzhouzhiwai
15th July 2013, 14:57
thank you. I understand.

I thought too much.