Results 1 to 7 of 7

Thread: Resizing height of dialog box dynamically

  1. #1
    Join Date
    Aug 2013
    Posts
    41
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    4

    Default Resizing height of dialog box dynamically

    hello,

    I have a dialog box with a list 3 QCheckBoxes items inside it. The visibility of last two items is connected to first QCheckbox.
    So, when the checkbox is 'on', the two items are visible and 'off' makes them invisible.
    By default, they are set invisible. So, when turn first checkbox 'on', the items appear and the height of dialog box is increased. So far fine.

    But when I turn it 'off', the items disappear leaving empty space in the layout (since the dialog box is now larger).
    How can I make the window height also resize (get shorter) when items are invisible?

    For example:
    Since I use a QVBoxLayout as the main layout in my dialog box:

    Qt Code:
    1. QVBoxLayout *MainLayout = new QVBoxLayout;
    2. MainLayout->addItem( new QSpacerItem(1,1,QSizePolicy::Expanding, QSizePolicy::Expanding));
    To copy to clipboard, switch view to plain text mode 

    Like the above lines resize the layout, how can I similarly resize the dialog-box height? Please help.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Resizing height of dialog box dynamically

    For example by calling resize(0, 0) on the dialog and let its layout figure out how much it has to increase its size again.

    Cheers,
    _

  3. #3
    Join Date
    Aug 2013
    Posts
    41
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    4

    Default Re: Resizing height of dialog box dynamically

    @anda: To shrink the layout, I have written lines in the slot function of my first QCheckBox as follows(lines for toggling visibility of items ans other stuff not shown) :

    void MyResizeTab()
    {
    MainLayout->addItem( new QSpacerItem(1,1,QSizePolicy::Expanding, QSizePolicy::Expanding)); //to shrink the layout
    resize(0, 0); //to shrink the dialog
    }

    It still does not shrink. May be because space is available in the lower part of layout. If I remove QSpacerItem, then the layout does not shrink! What is the way out?

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Resizing height of dialog box dynamically

    Is MyResizeTab a slot of the dialog class?
    Do you have any spacer items in the layout? Is their size hint small enouht? E.g. 0 or 1?

    Cheers,
    _

  5. #5
    Join Date
    Aug 2013
    Posts
    41
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    4

    Default Re: Resizing height of dialog box dynamically

    ya, the slot function is in the dialog class.

    I actually have 2 sub-layouts which added to the MainLayout. When the checkbox items are set visible, then the items are added vertically in the sub-layout, resulting in increase in the height of sub-layouts, mainlayout and hence the dialog box. Now, when the visibility is turned off, I can shrink back the layout to original size using:
    Qt Code:
    1. MainLayout->addItem( new QSpacerItem(1,1,QSizePolicy::Expanding, QSizePolicy::Expanding)); //to shrink the layout
    To copy to clipboard, switch view to plain text mode 
    But the height of the dialog box remains same (larger than original).
    What I want to have is when the items are invisible, the whole dialog box height should also reduce to the original height. In other words, currently the height only increases(when visibility 'on') but not decreases back (when visibility 'off').
    How can I make it work in both directions?

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: Resizing height of dialog box dynamically

    Can you explain to me how adding an expanding spacer is going to result in shrinking?

    In my understanding of the English language, which is limited due to not being my mother tounge, expanding is kind of the opposite if shrinking. Also adding doesn't sound like something that would result in less space being used.

    Cheers,
    _

  7. #7
    Join Date
    Aug 2013
    Posts
    41
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    4

    Default Re: Resizing height of dialog box dynamically

    @anda: You totally got me wrong. Let me explain.
    The reason I am adding QSpacerItem is to the layout is to shrink the layout when the objects are invisible. (I may be wrong in doing this).
    If I do not add the QSpacerItem, then the items above are spread all over the layout to accommodate the void caused by making the items invisible.
    I have added a picture (pict.jpg) which demonstrate the current behavior (steps 1-4) and ideal behavior (steps 5-7).
    Attached Images Attached Images
    Last edited by uz_qt; 9th November 2013 at 20:12.

Similar Threads

  1. Replies: 1
    Last Post: 5th March 2013, 08:04
  2. Row Height Resizing with QAbstractItemModel & QTreeView
    By dempsey001 in forum Qt Programming
    Replies: 0
    Last Post: 18th August 2011, 19:20
  3. resize Dialog to minimum height
    By pospiech in forum Qt Programming
    Replies: 7
    Last Post: 25th June 2009, 15:04
  4. Resizing the dialog box dynamically
    By vvbkumar in forum Newbie
    Replies: 5
    Last Post: 20th June 2006, 09:54
  5. Dynamically resizing in QT 3
    By kroenecker in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 19:37

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.