Solved Deleting widgets inside Qtabwidget page
-
I have a tab widget named blockTabWidget. There are multiple tabs in blockTabWidget. Each tab has its own layout and widgets. I populate the tabs by
blockTabWidget->addTab(new QWidget (),"TabName"); QVBoxLayout *layout; layout = new QVBoxLayout(); blockTabWidget->widget(index)->setLayout(layout); layout->addWidget(new QLabel("LAbel")); layout->addWidget(new LineEdit("Line1")); ... ...
If I do this in a function will it neatly remove all the tabs and delete all child widgets, layout ? Or do I have to remove all the childs , layout manually?
for (int i=blockTabWidget->count();i>0;i--) { blockTabWidget->widget(i-1)->deleteLater(); blockTabWidget->removeTab(i-1); }
Thanks
-
When you set a layout on a widget it becomes a child of that widget.
When you add a widget to a layout it becomes a child of the parent widget of that layout.
When you delete a widget it deletes all of its children.In short - yes, the way you did it everything in that tab will be deleted.
-
hi
for more info see
http://doc.qt.io/qt-5/objecttrees.html -
@Chris-Kawa Hi, thanks for the reply and explanation.