Qt - layout doesn't shrink when a widget is removed

1.6k views Asked by At

I'm working on a shape changing dialog. It's supossed to enlarge when a More button is hit and shrink when is hit again. What I do is use layout() -> addWidget() and layout() -> removeWidget(). It enlarges properly when I add a widget but when I remove something it doesn't shrink. I tried using layout() -> update() and layout() -> updateGeometry(), but none of them worked.

EDIT** Here's the functions I call when the buttons are clicked.

void findDialog::small()
{
    replaceBox -> hide();
    layout() -> removeWidget(replaceBox);
    moreButton -> show();
    updateGeometry();
}
void findDialog::extended()
{
    layout() -> addWidget(replaceBox);
    replaceBox -> show();
    moreButton -> hide();
    updateGeometry();
}

replaceBox is a QGroupBox

moreButton is a QPushButton

findDialog is a QDialog inherited class

1

There are 1 answers

0
Michael On

I solved it with layout() -> setSizeConstraint(QLayout::SetFixedSize); So now the widget's size is always set to sizeHint() That's why the layout wasn't updating as I wanted it to. This way updateGeometry() is not needed.