【发布时间】:2016-03-28 01:30:53
【问题描述】:
我有一个包含其他布局(子布局)的布局。我需要从布局中删除带有内容的子布局。我该怎么办?
QVBoxLayout* mainLayout = new QVBoxLayout;
QHBoxLayout* subLayout = new QHBoxLayout;
for(int i = 0; i < 3; i++)
subLayout->addWidget(new QPushButton(this)); //some content of sublayout
mainLayout->addLayout(subLayout);
setLayout(mainLayout);
这个类中只有QLayout::removeWidget(),但没有QLayout::removeLayout() 这样的东西。只是
delete subLayout 或
QLayoutItem *item;
while ((item = subLayout->takeAt(0)))
delete item;
delete subLayout;
也没有正确的效果(内容仍然保留在屏幕上)。
那怎么办?
【问题讨论】:
-
如果父层次结构正确,
delete subLayout应该可以工作,AFAIK。