As a generic answer: taken from here with slight, but important changes: you should not call widget.deleteLater(). At least in my case this caused python to crash
Global Function
def deleteItemsOfLayout(layout):
if layout is not None:
while layout.count():
item = layout.takeAt(0)
widget = item.widget()
if widget is not None:
widget.setParent(None)
else:
deleteItemsOfLayout(item.layout())
together with the boxdelete function from Brendan Abel's answer
def boxdelete(self, box):
for i in range(self.vlayout.count()):
layout_item = self.vlayout.itemAt(i)
if layout_item.layout() == box:
deleteItemsOfLayout(layout_item.layout())
self.vlayout.removeItem(layout_item)
break
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…