Widget setVisible(false) without layout changing ?
-
wrote on 11 Jun 2015, 10:07 last edited by Andy314 6 Nov 2015, 18:08
Is it possible make a widget invisible (not drawn), so that the layout manager preserves the same space as before for it ?
-
Lifetime Qt Championwrote on 11 Jun 2015, 23:03 last edited by SGaist 6 Dec 2015, 07:30
Hi,
I'm not sure I'm following correctly, what would you like to achieve ?
-
Is it possible make a widget invisible (not drawn), so that the layout manager preserves the same space as before for it ?
@Andy314 I guess you will need to insert an empty
QWidget
or a QSpacerItem. -
After getting some sleep… You could use a QStackedWidget/Layout with an empty widget in. When you want to "hide" your main widget, just change the current widget of the stack.
-
wrote on 12 Jun 2015, 11:28 last edited by
Sometimes it is more logical to hide a widget instead of disabling it.
(Button funktion makes in the current state no sense - a info text is not needed, etc.)
But I want avoid the resizing/moving of the other widgets, so that the dialog stays stable.
(Widget keeps the same sizeHint but draw itself as invisible.)
I tested:
The trick with the empy widget and an invisible widget in it works very well.
QStackedWidget must work too.Is there a special page, where some common tricks for the Qt GUI designing are explained ?
-
Not that I know of but the wiki is pretty big (and currently in a cleanup phase)
-
Is it possible make a widget invisible (not drawn), so that the layout manager preserves the same space as before for it ?
wrote on 18 Mar 2019, 12:21 last edited by@Andy314
Hi
Sorry if I use this post for an updating,
I want to do same thing in Qt 4.X and I have found this post:https://stackoverflow.com/questions/1874426/hiding-qt-widget-and-keeping-widget-space
The tip is using QsizePolicy, for example:
QSizePolicy sp_retain = ui->label_3->sizePolicy(); sp_retain.setRetainSizeWhenHidden(true); ui->label_3->setSizePolicy(sp_retain); ui→label_3→hide();
Unfortunately is not possible to use in Qt 4 but only in Qt5 :(
Regards