Qt World Summit: Register Today!

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();
    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--)


  • Moderators

    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.

  • Lifetime Qt Champion

  • @Chris-Kawa Hi, thanks for the reply and explanation.

Log in to reply