Results 1 to 4 of 4

Thread: Custom Window : block app during resize

  1. #1
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Exclamation Custom Window : block app during resize

    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

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Custom Window : block app during resize

    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..
    Last edited by d_stranz; 21st February 2017 at 05:00.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Custom Window : block app during resize

    Quote Originally Posted by Alundra View Post
    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/5291...-resizing-done
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  4. The following user says thank you to Santosh Reddy for this useful post:

    Alundra (21st February 2017)

  5. #4
    Join Date
    May 2013
    Posts
    321
    Thanks
    9
    Thanked 8 Times in 8 Posts
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom Window : block app during resize

    Great idea to use a timer to execute a delayed resize !

Similar Threads

  1. Replies: 1
    Last Post: 29th December 2013, 19:06
  2. Replies: 1
    Last Post: 28th January 2012, 14:59
  3. Replies: 1
    Last Post: 18th July 2011, 16:24
  4. Replies: 0
    Last Post: 1st February 2010, 12:00
  5. Replies: 0
    Last Post: 2nd June 2009, 16:57

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.