Derived QLayouts not owning added Items?
bq. Note: The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.
where qWidget has a QGridLayout
doesn't delete items of the layout in the qWidget added via addWidget to the layout.
How to do this?
Your derived QLayout should delete the items in its destructor, see the example there: http://qt-project.org/doc/qt-5.0/qtwidgets/layout.html#the-implementation-file-card-op-op-cpp
derived was referring to Qts derived layouts. I use a QGridLayout. It does not delete its items. As deleting the layouts items myself has no effect, I wonder whether it's just display remnants as I'm seeing the new layouts items I set afterwards on top of the old layouts items in my qWidget. Something else to consider? Despite that, thank you for your answer!
It does delete the items, but the widgets are not the items, their position is controlled by them. So when you delete the layout, the widgets that it contained stay where they last were.
You should delete the widgets manually and possibly recursively (if the layout contains other layouts), or delete the whole widget that contains the layout and recreate both.
Or you could use "that trick":http://stackoverflow.com/questions/4857188/clearing-a-layout-in-qt/7082920#7082920 .