|
1Qter豆
本帖最后由 xuyinghua 于 2017-4-17 10:02 编辑
我在主窗口的中心区域,需要根据不同的情况设置不同的部件。在向中心区域添加布局和部件之前,先将原有的布局和部件删除,代码如下: //先清除主窗口中心区域的布局
QLayout *layout = ui->centralWidget->layout();
if(layout)
{
QLayoutItem *child;
while((child=layout->takeAt(0))!=0)
{
delete child;
}
delete layout;
}
//定义要添加的子窗口部件
MenuArea *menuWidget = new MenuArea(configType);
ModConfig *tableWidget = new ModConfig;
//向主窗口中心区域添加布局和部件
QHBoxLayout *horizontalLayout = new QHBoxLayout;
horizontalLayout->setSpacing(6);
horizontalLayout->setContentsMargins(6,6,6,6);
horizontalLayout->addWidget(menuWidget);
horizontalLayout->addWidget(tableWidget);
horizontalLayout->setStretch(0, 1);
horizontalLayout->setStretch(1, 3);
ui->centralWidget->setLayout(horizontalLayout);
程序运行后,布局删除了,但是布局里的部件没有删除,和后来的部件显示时重叠了。怎么才能将中心区域的布局和布局里的部件一起删除?
|
|