How to delete QTreeWidgetItem

后端 未结 4 2059
没有蜡笔的小新
没有蜡笔的小新 2021-02-20 02:42

Several webpages say that QTreeWidgetItem can be deleted by deleting or QTreeWidget.clearing. But my code sample below doesn\'t seem to do so. Am I doi

4条回答
  •  旧巷少年郎
    2021-02-20 03:29

    By calling del i you are just deleting the reference not the actual C++ Object(referent) it refers to, not the object itself.

    Change your TreeWidgetItemChild.__del__ function to:

    def __del__(self):
        treeWidget = self.treeWidget()
        #removing the QTreeItemWidget object
        treeWidget.takeTopLevelItem(treeWidget.indexOfTopLevelItem(self))
        print 'TreeWidgetItemChild del'
    

提交回复
热议问题