Qt - Clear all widgets from inside a QWidget's layout

前端 未结 3 1367
悲&欢浪女
悲&欢浪女 2021-01-12 02:18

I have a QWidget in a dialog. Over the course of the program running, several QCheckBox * objects are added to the layout like this:



        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-12 02:26

    You can try this:

        while ( QLayoutItem* item = ui->myWidget->layout()->takeAt( 0 ) )
        {
            Q_ASSERT( ! item->layout() ); // otherwise the layout will leak
            delete item->widget();
            delete item;
        }
    

提交回复
热议问题