Problems with Open-Source Downloads read and

QStackedWidget hiding pages

  • Hi all,

    I want to hide pages of a stacked widget, because I have a Dialog with multiple contents. Each page has a different size due to the different widgets on the page, e. g. "Single" is very small (200x300 pixels) and "Multi" is very big (1000x600 pixels) (see code below). So the Dialog should be resized to fit its current visible content. But this does not work if the other pages are still visible, so hiding them would be a good idea.

    In Header File:

    enum Type { Single, Multi, Other };

    In Source File:

    void FormDialog::setPage( Type type )
        ui->page_single->setVisible( type == Single );
        ui->page_multi->setVisible( type == Multi );
        ui->page_other->setVisible( type == Other );

    But this does not work.
    It works if I insert groupboxes as children of the pages and the other widgets in the groupboxes and hide the groupboxes.
    What's the problem here?


  • My first thought is that QGroupBox probably provides a sizehint() that is zero if the widget is not visible where your other widget probably does not do this.

    The QStackedWidget would provide a sizehint() based on all of the children. When you hide the children you make the end result no smaller than the largest child.

    Another idea to implement this is to have a common set of options always visible and show/hide the additional parts that are unique to the 'multi' and 'other' views. This will autosize.