gpt4 book ai didi

qt - 如何删除小部件上已经存在的布局?

转载 作者:行者123 更新时间:2023-12-04 00:04:05 26 4
gpt4 key购买 nike

You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout.



来自 http://doc.qt.io/qt-5.9/qwidget.html#setLayout

哪个函数用于删除以前的布局?

最佳答案

克里斯威尔逊的回答是正确的,但我发现布局不会删除它下面的子布局和 qwidgets。如果您有复杂的布局或可能有内存泄漏,最好手动进行。

QLayout * layout = new QWhateverLayout();

// ... create complicated layout ...

// completely delete layout and sublayouts
QLayoutItem * item;
QLayout * sublayout;
QWidget * widget;
while ((item = layout->takeAt(0))) {
if ((sublayout = item->layout()) != 0) {/* do the same for sublayout*/}
else if ((widget = item->widget()) != 0) {widget->hide(); delete widget;}
else {delete item;}
}

// then finally
delete layout;

关于qt - 如何删除小部件上已经存在的布局?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7528680/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com