PDA

View Full Version : main window doesn't re-size when child widget hidden



sandsaturn22
28th August 2013, 04:01
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.

wagmare
28th August 2013, 04:26
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/layout.html#stretch-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 ..

ChrisW67
28th August 2013, 04:39
Take a look at the Extension Example in Assistant

sandsaturn22
28th August 2013, 12:53
The piece I was missing is:

QLayout::setSizeContraint(QLayout::SetFixedSize)
Thats what is needed to cause the widget to resize down to the size hint. Thanks for your help ChrisW67.