2

I have a qwidget (we'll call it qwidget1) inside of a layout of an other qwidget (we'll call it qwidget2), I want to delete everything that is in the layout of qwidget2: I would like to clear the layout so there's nothing in it anymore .. what I can do so far is remove completely the qwidget2 by doing:

void QCell::deleteMyChildren(){
   delete this;
}

but it removes the qwidget2 itself.. that's not what I want. Please help me remove the items that are inside the layout.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Ben
  • 469
  • 2
  • 4
  • 20

1 Answers1

2

just loop inside the items in the layout and remove item from layout, then delete item :

void QCell::deleteMyChildren() {
    while (count() > 0) {
        QLayoutItem * item = takeAt(0);
        delete item;
    }
}
TheBootroo
  • 7,408
  • 2
  • 31
  • 43