I add a layout in a dialog and sometimes I want it and all its containing widgets to hide. How to implement it? I try layout->setEnable(false)
, but it doesn't seem to work in my tests.
2 Answers
You can't do that. You should add a widget in your form, put children inside the widget and assign desired layout to the widget. The behavior will be generally the same, but you can use setVisible
or hide
methods of the widget.
3
-
1While Pavel's answer is kinda correct, the "You can't do that." bit is misleading. This answer is more useful, as it shows a handy UI-diven way to achieve the desired result in a couple of clicks. You can do that.– M_MJul 3, 2018 at 13:09
-
1@M_M Imo, no you can't do that. You can't call hide on the layout. You need to convert the layout to a widget, exactly what Pavel's answer says. This answer does not provide extra info. Who cares about the GUI.– SwedginOct 21, 2020 at 11:25
-
@Swedgin: I'm not sure what you mean when you say "Who cares about the GUI". This is about QLayout and QWidget - those are both GUI elements, so I think probably everyone who reads this question cares about the GUI, and at least the 23+ people who upvoted this answer... Also, just realised that maybe you meant who cares about a GUI-driven way to solve the OP's question. Same answer - at least 23 people.– M_MOct 21, 2020 at 15:39