Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Deleting widgets inside Qtabwidget page
Qt 6.11 is out! See what's new in the release blog

Deleting widgets inside Qtabwidget page

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 4.7k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UHaider
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      U 1 Reply Last reply
      2
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        hi
        for more info see
        http://doc.qt.io/qt-5/objecttrees.html

        1 Reply Last reply
        2
        • Chris KawaC Chris Kawa

          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.

          U Offline
          U Offline
          UHaider
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved