tags:

views:

32

answers:

2
+1  Q: 

auto adjustSize()

Hi, my widget has children widgets which can appear and disappear sometimes. Now after hiding one of child I call adjustSize() to resize the main widget to possible minimum.

How to automatically call adjustSize() when showing/hiding children in a layout? I tried setting sizePolicy to QSizePolicy::Minimum but this doesn't help...

+1  A: 

When you call

QWidget::setVisibility(true/false)
QWidget::hide()
QWidget::show()

it generates a showEvent or a hideEvent see doc here. So, what you could do is to install an eventFilter on your widget to check when the showEvent is called and then call adjustSize when it is required.

See doc here for details about the event filter.

Hope that helps.

Live
A: 

Setting a minimum size constraint on the main widget's layout should solve your problem:

mainWidget->layout()->setSizeConstraint(QLayout::SetMinimumSize);
Ton van den Heuvel