找回密码
 立即注册
收起左侧

删除布局里的部件

0
回复
7319
查看
[复制链接]
累计签到:53 天
连续签到:1 天
来源: 2017-4-17 09:55:33 显示全部楼层 |阅读模式
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);
程序运行后,布局删除了,但是布局里的部件没有删除,和后来的部件显示时重叠了。怎么才能将中心区域的布局和布局里的部件一起删除?




回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了