how to hide the horizontalLayout?
QT 隐藏布局Layout中的控件
===============================
how to hide the horizontalLayout?
A layout can not be hidden since they are not widgets and does not have a setVisible() function.
You have to create a widget that you can hide, that contains the layout and the other widgets that should be hidden, then you hide the widget instead of the layout.
QWidget* myWidget = new QWidget();
QHBoxLayout * layout = new QHBoxLayout(myWidget);
layout->addWidget(new QLabel("Label"));
myWidget->setVisible(false);
QT 隐藏布局Layout中的控件
隐藏整个布局控件
先获取所有子控件,然后隐藏
for (int i = 0; i < ui->horizontalLayout->count(); ++i) {
QWidget* w = ui->horizontalLayout->itemAt(i)->widget();
if (w != NULL)
w->setVisible(false);
}
https://blog.csdn.net/wangmingshi666/article/details/122216764