删除 QScrollArea 的小部件
deleting widget of QScrollArea
我必须根据左侧树项目的选择来更新或更改 scrollArea 内的小部件。
QWidget *scrollAreaWidget = new QWidget;
scrollAreaWidget->setObjectName("ScrollAreaWidget");
QVBoxLayout *scrollLayout = new QVBoxLayout;
scrollAreaWidget->setLayout(scrollLayout);
foreach (PyInfo pInfo, list) {
//Adding widget
rowWidget->setObjectName(objName);
scrollLayout->addWidget(rowWidget);
}
m_pScrollArea->setWidget(scrollAreaWidget);
所以当我需要更新一个新的小部件时,我试图像这样清除添加到 scrollArea 的旧小部件
QWidget *wid = m_pScrollArea->widget();
if(wid)
wid->deleteLater();
是 deleteLated() 调用就足够了,否则我必须明确删除我作为子项添加到 ScrollArea->widget() 的所有小部件并断开其中的信号。
是的,这应该足够了。 Qt 负责其余的工作。来自 Qt 文档:
The parent takes ownership of the object; i.e., it will automatically
delete its children in its destructor.
......
A signal-slot connection is removed when either of the objects
involved are destroyed.
我必须根据左侧树项目的选择来更新或更改 scrollArea 内的小部件。
QWidget *scrollAreaWidget = new QWidget;
scrollAreaWidget->setObjectName("ScrollAreaWidget");
QVBoxLayout *scrollLayout = new QVBoxLayout;
scrollAreaWidget->setLayout(scrollLayout);
foreach (PyInfo pInfo, list) {
//Adding widget
rowWidget->setObjectName(objName);
scrollLayout->addWidget(rowWidget);
}
m_pScrollArea->setWidget(scrollAreaWidget);
所以当我需要更新一个新的小部件时,我试图像这样清除添加到 scrollArea 的旧小部件
QWidget *wid = m_pScrollArea->widget();
if(wid)
wid->deleteLater();
是 deleteLated() 调用就足够了,否则我必须明确删除我作为子项添加到 ScrollArea->widget() 的所有小部件并断开其中的信号。
是的,这应该足够了。 Qt 负责其余的工作。来自 Qt 文档:
The parent takes ownership of the object; i.e., it will automatically delete its children in its destructor.
......
A signal-slot connection is removed when either of the objects involved are destroyed.