删除QScrollArea的小部件

时间:2016-01-08 07:19:18

标签: qt qwidget

我必须更新或更改scrollArea中的小部件,具体取决于左侧树项的选择。

.button a { 
-webkit-border-radius: 5px;
-moz-border-radius: 5px;
border-radius: 5px;
-webkit-box-shadow: 4px 4px 5px 0px rgba(204, 204, 204, 1);
-moz-box-shadow:    4px 4px 5px 0px rgba(204, 204, 204, 1);
box-shadow:         4px 4px 5px 0px rgba(204, 204, 204, 1);
margin-left:30px;
line-height: 20px;

padding:10px 10px;
background-color:#009e57;
display:block;
color:#fff;
text-align: center;
margin-bottom: 10px;
margin-top: 10px;

 }

所以当我需要更新新的小部件时,我试图清除像这样添加到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);

是deleteLated()调用就足够了,或者我必须明确删除我作为子项添加到ScrollArea-> widget()的所有小部件,并断开其中的信号。

1 个答案:

答案 0 :(得分:1)

是的,这应该足够了。 Qt关心其余部分。从Qt文档:

  

父母取得对象的所有权;即,它会自动   在析构函数中删除它的子项。

     

...

     

当任一对象移除信号槽连接时   参与被摧毁。