In Qt4, how to check if paintEvent is caused by resizing?

In a Qt4 application, is it possible to specify inside the paintEvent() handler, was the redraw caused by resizing or not?

I have a widget that redraws very slowly (complex plot), and I want to speed up the resizing by simply blitting the resized pixmap size map when the widget is resized and only redraw the widget when the size is complete.

I tried to set / disable the flag at the beginning and end of resizeEvent() , but this does not work (i.e. the flag is always off in paintEvent() ).

+4
source share
3 answers

I do not think you can do this easily. It's hard to say when resizing started / stopped, especially in cross-platform form. I would probably have a one-shot timer that fires under resizeEvent , which displays the image on a QPixmap . If you get another resizeEvent while the timer is still active, just restart it. In paintEvent always draw the current pixmap, and after rendering the new pixmap from the timer, call update() on the widget. Not an ideal solution, but it should work.

+6
source

One approach you can take is to always draw a pixmap, but remember to recreate the pixmap “soon” if the window size has changed.

So, when paintEvent appears, if the size differs from the current pixmap size, then color the saved pixmap anyway, but then set (or reset) a QTimer to trigger a signal in the slot that will update pixmap.

When this update method is launched, it will re-render the pixmap and request a widget update.

+3
source

Another possibility is to see how QMdiSubWindow :: RubberBandResize is implemented internally, it can give hints on how to achieve this. It works only on QMdiSubwindow, if I remember correctly - it "stops" drawing (except for the small border of the window with a transparent body) during resizing and starts one last resizeEvent (which starts updating / paint) when the window resizes ...

+1
source

All Articles