Widget setVisible(false) without layout changing ?
-
Is it possible make a widget invisible (not drawn), so that the layout manager preserves the same space as before for it ?
-
Hi,
I'm not sure I'm following correctly, what would you like to achieve ?
-
@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.
-
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)
-
@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