PDA

View Full Version : Stop repaint while scrolling in paintEvent()



sagirahmed
26th October 2010, 05:20
Hi,

I have draw thousand of lines using paintEvent(). When I scroll or minimize the widget the paintEvent call again and again start drawing the same drawn line again and again. How can I stop to call paintEvent when we scrolling or minimize. I want that we draw a line once then there is no need to draw the same line again and again while minimize or scroll.

Thanks & Regards
Sagir Ahmed

tbscope
26th October 2010, 05:41
Hi,

I have draw thousand of lines using paintEvent(). When I scroll or minimize the widget the paintEvent call again and again start drawing the same drawn line again and again.

Be sure not to loop the paint event. This means, do not call the paint event from within the paint event, do not update the widget in any way inside the paint event.

Use a trigger timer. Set it to, for example, 50ms. Inside that time, the paintEvent will just return. Outside that interval, the paint event will be executed and the trigger timer restarted. Of course, that will lead to uglyness. At least paint some parts of the widget, but maybe not its calculation heavy contents.


How can I stop to call paintEvent when we scrolling or minimize.
See above.


I want that we draw a line once then there is no need to draw the same line again and again while minimize or scroll.
Use a buffer.

sagirahmed
26th October 2010, 06:01
Hi,

Actully paintEvent call automatically when I minimize or do some event on Widget. I want to stop the calling of paintEvent again and again Once I have drawn the line.

tbscope
26th October 2010, 06:07
Hi,

Actully paintEvent call automatically when I minimize or do some event on Widget.

Yes, I know, but that is not what I meant. This is normal and should not be changed.


I want to stop the calling of paintEvent again and again Once I have drawn the line.

Like I said above, use a buffer, an image if you will, and instead of drawing lines, you draw the image.

Or, and this is not very easy if you're a beginner, use QtConcurrent to draw the contents in a picture. Then use a future watcher to paint the finished picture. Let the future update when the widget changed.

sagirahmed
26th October 2010, 06:21
Hi,

Is this possible to create the image(QImage or QPixmap) that i have drawn using paintEvent(), If i will able to create the image that I have drawn then this image will be easily set to any QLabel with scrolling.