C++ 如何从其他QLayout中删除QLayout?
我有一个包含其他布局(子布局)的布局。我需要从布局中删除包含内容的子布局。我怎么能做到C++ 如何从其他QLayout中删除QLayout?,c++,qt,C++,Qt,我有一个包含其他布局(子布局)的布局。我需要从布局中删除包含内容的子布局。我怎么能做到 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
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);
也没有正确的效果(内容仍保留在屏幕上)
那么怎么做呢?
void QLayout::removietem(QLayoutItem*item)
从布局中删除布局项。这是打电话的人的电话
删除该项目的责任
请注意,项可以是布局(因为QLayout继承了QLayoutItem)
void QLayout::removietem(QLayoutItem*item)
从布局中删除布局项。这是打电话的人的电话
删除该项目的责任
请注意,项可以是布局(因为QLayout继承了QLayoutItem)
delete subLayout
如果父层次结构正确,则应该工作,AFAIK。delete subLayout
如果父层次结构正确,则应该工作,AFAIK。
QLayoutItem *item;
while ((item = subLayout->takeAt(0)))
delete item;
delete subLayout;