Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save excalamus/aaf6eb51e6648825f54f97aa4ff37213 to your computer and use it in GitHub Desktop.
Save excalamus/aaf6eb51e6648825f54f97aa4ff37213 to your computer and use it in GitHub Desktop.
Pyside + Python: Remove items from a layout
def clear_layout(self, layout):
while layout.count():
child = layout.takeAt(0)
if child.widget() is not None:
child.widget().deleteLater()
elif child.layout() is not None:
clear_layout(child.layout())
def clear_layout(self, layout):
for x in reversed(range(layout.count())):
widget = layout.takeAt(x).widget()
if widget is not None:
widget.deleteLater()
else:
clear_layout(layout.takeAt(x).layout())
def clear_layout(self, layout):
for i in reversed(range(layout.count())):
layout.itemAt(i).widget().setParent(None)
def clear_layout(self, layout):
while layout.count():
item = layout.takeAt(0)
widget = item.widget()
if widget is not None:
widget.deleteLater()
else:
clear_layout(item.layout())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment