I know this question is old and answered, but: since QtAlgorithms offers qDeleteAll , you can delete the layout, including deleting all its children with a single line.
This is a repetition of the text that I posted here: https://stackoverflow.com/a/316677/
This code deletes the layout, all its children and everything inside the layout disappears.
qDeleteAll(yourWidget->children());
Here is a description of the overloaded function:
void qDeleteAll (ForwardIterator begin, ForwardIterator end)
Deletes all elements in the range [start, end] using the C ++ operator delete>. The type of the element must be a pointer (for example, QWidget *).
Note that qDeleteAll must be passed with the container from this widget (and not this layout). And note that qDeleteAll does NOT delete yourWidget - only its children.
Now a new layout can be installed.
mw
source share