How to hide all widgets from a QVBoxLayout with spacer?
Solved
General and Desktop
-
Hey,
I have created this GUI in Qt Creator.
Now I want to make some kind of edit mode. For this I want to hide the left layout of the image completely. I have tried this:
void MainWindow::activateEditMode() const { for (int widgetNumber = 0; widgetNumber < ui->modelLayout->count(); widgetNumber++) { ui->modelLayout->itemAt(widgetNumber)->widget()->hide(); } }
However, the program crashes with a segmentation fault if the spacer is to be "hidden". What I have also read that layouts can not be hidden. What is the best way to do something like this?
-
Hi,
Check that the returned value of
widget()
is not null. -
@Gabber said in How to hide all widgets from a QVBoxLayout with spacer?:
The "morph into" function in the QT creator does exactly what you write, doesn't it? There I can also convert the layout into a QWidget.
I have hard time to figure out how to convert (morph?) a layout to a widget.