如何从其他QLayout中删除QLayout
How to remove QLayout from other QLayout?
我有一个包含其他布局(sublayout)的布局。我需要从布局中删除包含内容的子层。我该怎么做?
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;
也没有正确的效果(内容仍然保留在屏幕上)。
那么怎么做呢?
void QLayout::removeItem(QLayoutItem *item)
从布局中删除布局项项目。这是来电者的删除项目的责任。
请注意,项可以是布局(因为QLayout继承了QLayoutItem)。
相关文章:
- 将数组的地址分配给变量并删除
- 删除一个线程上有数百万个字符串的大型哈希映射会影响另一个线程的性能
- C/C++编译器通常会删除重复的库吗
- 从链接列表c++中删除一个项目
- C++如何通过用户输入删除列表元素
- 为什么在C++中使用私有复制构造函数与删除复制构造函数
- 是否需要删除包含对象的"pair"?
- 如何在自删除后将对象设置为nullptr
- 迭代时从向量和内存中删除对象
- 使用函数"remove"删除重复元素
- 如何从多映射中删除特定的重复项
- 运算符C++ "delete []"仅删除 2 个前值
- 删除指向指针的指针是运行时错误吗
- 将指针设置为"nullptr"并不能防止双重删除?
- 为什么示例代码访问IUnknown中已删除的内存
- 如何通过 getter 函数删除矢量的元素?
- 从控制台中删除最后打印的元素
- C++中的线程安全删除
- 在 QLayout 中创建和删除自定义 QWidgets 时出现 RAM 问题
- 如何从其他QLayout中删除QLayout