Solved Cleaning QFormLayout
-
Hi,
I'm using a QFormLayout to display rows of QString and QSpinBox
I need to clean the content of my layout to add new row.I have tried things like removeItem(itemAt()) but it's not working, i still have some labels superposition.
Thx
EDIT : I have also tried takeAt(0) but i have error like : QFormLayout::takeAt: Invalid index 0
-
Hi
The layout owns the widgets so u should use
takeAt to transfer ownership back if you plan on deleting the
"row" widgets u remove.try this for clean all.
void clearLayout(QLayout *layout) { if (layout) { while(layout->count() > 0){ QLayoutItem *item = layout->takeAt(0); delete item->widget(); delete item; } } }
-
Ha ok !
I have also tried to delete the item but i thought i was automatically deleting the widget.
Thx :)
-
One would assume that QLayoutItem owns the widget and deletes it.
I never tested it :)Sounds like it wont ?
-
@mrjj
Tried by adding comment to : delete item->widget();Didn't work
-
@Zoptune
Ok, thanks.
so QLayoutItem dont own the widget, it really is the layout. :) -
Hi,
There's currently no way to directly remove or remove + delete content of a QFormLayout. But there's a work in progress patch for that.