Several webpages say that QTreeWidgetItem
can be deleted by deleting or QTreeWidget.clear
ing. But my code sample below doesn't seem to do so. Am I doing anything wrong?
#!/usr/bin/python
import sys
from PySide.QtGui import QApplication, QWidget, QTreeWidget, QTreeWidgetItem
#from PyQt4.QtGui import QApplication, QWidget, QTreeWidget, QTreeWidgetItem # Result was the same with `PySide`
import time
class TreeWidgetItemChild(QTreeWidgetItem):
def __init__(self):
super(TreeWidgetItemChild, self).__init__()
print 'TreeWidgetItemChild init'
def __del__(self):
print 'TreeWidgetItemChild del'
def test_QTree_clear_children():
tree = QTreeWidget()
tree.setHeaderLabel('funksoul')
i = TreeWidgetItemChild()
tree.addTopLevelItem(i)
print 'Before clearing'
#tree.clear() # Didn't call destructor (__del__)
#tree.removeItemWidget (i, 0) # Didn't call destructor
#i.__del__() # Called destructor but it's called again afterward
del i # Didn't call destructor
time.sleep(1)
print 'After clearing'
if __name__ == '__main__':
app = QApplication(sys.argv)
test_QTree_clear_children()
Printed as:
TreeWidgetItemChild init
Before clearing
After clearing
TreeWidgetItemChild del
Looks to me TreeWidgetItemChild
gets deleted upon the termination of process, not by any of my deletion actions.