Last active
October 17, 2020 18:51
-
-
Save tcrowson/8273931 to your computer and use it in GitHub Desktop.
For PyQt/PySide. A simple function for clearing the contents of a QTreeWidget/QTreeView, since these classes lack convenient clear() or clearContents() methods. Takes a QTreeWidget or QTreeView object as an argument.
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
import PySide | |
from PySide import QtGui | |
def clearQTreeWidget(tree): | |
iterator = QtGui.QTreeWidgetItemIterator(tree, QtGui.QTreeWidgetItemIterator.All) | |
while iterator.value(): | |
iterator.value().takeChildren() | |
iterator +=1 | |
i = tree.topLevelItemCount() | |
while i > -1: | |
treeWidget.takeTopLevelItem(i) | |
i -= 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For PySide2