Results 1 to 4 of 4

Thread: main window doesn't re-size when child widget hidden

  1. #1
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default main window doesn't re-size when child widget hidden

    Hello,

    I am designing a UI in which certain user actions (clicking check boxes) can result in various widgets on the UI being hidden or shown. I notice when widgets are shown the layout management system will increase the size of the GUI to accommodate to new items. However in contrast when the widgets are hidden the layout simply resizes/redistributes the existing widgets to fill the leftover space but does not actually reduce the overall size of the top level window. This behavior is not desired, instead I would like the window to actually shrink.

    A few questions:

    1.) Is there a way to automatically tell a layout to behave in this manner? I havn't found one if there is.

    2.) What signal does the layout management system catch (or what event) to know when child widgets have been hidden? Looking at the documentation it doesnt look like a show() or hide() signal is emitted from QWidget.
    Last edited by sandsaturn22; 28th August 2013 at 04:17.

  2. #2
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: main window doesn't re-size when child widget hidden

    a small suggestion .. but though i wont be a right approach
    use stretch factors vertical stretch or horizontal stretch and spacers
    http://qt-project.org/doc/qt-4.8/qspaceritem.html
    and
    http://qt-project.org/doc/qt-4.8/lay...tretch-factors

    spacer will make the area reserve for the widget u show and hide..

    instead I would like the window to actually shrink
    resizeEvent() and setFixedSize() can help u ..
    "Behind every great fortune lies a crime" - Balzac

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: main window doesn't re-size when child widget hidden

    Take a look at the Extension Example in Assistant
    "We can't solve problems by using the same kind of thinking we used when we created them." -- Einstein
    If you are posting code then please use [code] [/code] tags around it - makes addressing the problem easier.

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

    sandsaturn22 (28th August 2013)

  5. #4
    Join Date
    Aug 2013
    Posts
    5
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: main window doesn't re-size when child widget hidden

    The piece I was missing is:
    Qt Code:
    1. QLayout::setSizeContraint(QLayout::SetFixedSize)
    To copy to clipboard, switch view to plain text mode 
    Thats what is needed to cause the widget to resize down to the size hint. Thanks for your help ChrisW67.
    Last edited by sandsaturn22; 28th August 2013 at 13:21.

Similar Threads

  1. Guide needed for layout management
    By sikander243 in forum Newbie
    Replies: 1
    Last Post: 14th March 2013, 11:02
  2. Layout management thoughts required
    By ChrisW67 in forum Qt Programming
    Replies: 2
    Last Post: 5th July 2011, 23:58
  3. Replies: 3
    Last Post: 30th May 2008, 07:37
  4. Replies: 3
    Last Post: 4th April 2008, 19:51
  5. Layout Management Issues
    By dave in forum Newbie
    Replies: 3
    Last Post: 5th November 2006, 18:16

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
  •  
Qt is a trademark of The Qt Company.