Qt 如何从表单中删除QHBoxLayout
我使用此代码从表单中清除所有现有控件Qt 如何从表单中删除QHBoxLayout,qt,qt5,Qt,Qt5,我使用此代码从表单中清除所有现有控件 QFormLayout *formLayoutFunction; void DeleteExistingControls() { QLayoutItem *child; comboBoxFunctions->blockSignals(true); comboBoxFunctions->clear(); comboBoxFunctions->bloc
QFormLayout *formLayoutFunction;
void DeleteExistingControls()
{
QLayoutItem *child;
comboBoxFunctions->blockSignals(true);
comboBoxFunctions->clear();
comboBoxFunctions->blockSignals(false);
while ((child = formLayoutFunction->takeAt(0)) != 0) {
delete child->widget();
delete child;
}
}
问题是,在执行此函数之后,QHBoxLayout的小部件仍然存在
在表单中,我有多个QHboxLayout,我想将它们全部删除。这就是我删除QHboxLayout小部件的方式
while ((child = formLayoutFunction->takeAt(0)) != 0) {
if (child->layout() != 0)
{
QLayout *ly = child->layout();
QLayoutItem* layoutItem ;
while (ly->count() != 0){
layoutItem = ly->takeAt(0);
delete layoutItem->widget();
delete layoutItem;
}
}
delete child->widget();
delete child;
}
您不会删除布局,那么您希望看到什么?我想删除布局,但我的当前代码不删除布局。我想删除布局和布局中的所有小部件。布局不是C++对象的容器,它只管理GUI对象的布局。