Forked from JokerMartini/Remove Items From Layout | .py
Created
April 27, 2021 15:13
-
-
Save excalamus/aaf6eb51e6648825f54f97aa4ff37213 to your computer and use it in GitHub Desktop.
Pyside + Python: Remove items from a layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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