PDA

View Full Version : Custom Window : block app during resize



Alundra
21st February 2017, 03:24
Hi,
I made a custom window and I handle manually the resize, all works good but during the resize the window continue to update.
Is it possible to block completely the app during the resize and enable it again once the resize action is finished ?
Thanks

d_stranz
21st February 2017, 03:52
Probably the easiest way to do this is to use a QTimer and a Boolean member variable that you set when the windows is resizing. When you get the first resize event, set the Boolean to true and start the timer with a short timeout (say 250 ms). Each time you get another resize event, you stop the timer if it is still running and then restart it. In your paint event, you check the Boolean to see if you are in the middle of the resize. If you are, then you don't do anything, otherwise you process your paint event normally.

In the QTimer's timeout handler, you set the Boolean to false and call update() for force a repaint.

The logic is that as long as the user is resizing the window, the timer will continue to be reset and the paint event bypassed. Once the mouse stops moving, the timer fires and the window repaints. You could do this without the Boolean and simply check QTimer::isActive() in the paint event, but I prefer having the Boolean just for debugging purposes.

It usually makes things look nicer to not completely ignore the paint event, but to paint something else (like just fill the window rect) so the user isn't looking at some partially painted window. If you wanted to get really fancy, you could render the window to a pixmap at the start of the resize, and then paint it to the window with scaling. It'll give the impression of a resized window but without the overhead of repainting the real thing..

Santosh Reddy
21st February 2017, 03:58
Hi,
..all works good but during the resize the window continue to update.

What do mean by update? Do you mean widget re-laying out child widgets, or is there any animation in the widget / child widget?

It sounds like that you need to add a pause and resume feature to your App.

Anyway take a look at Chris's suggestion in this post, may be that's what you need
http://www.qtcentre.org/threads/52916-window-resizing-done

Alundra
21st February 2017, 17:11
Great idea to use a timer to execute a delayed resize !