PyQtでTreeViewからすべてのノードを削除するには?
全てのノードを削除するには
root = treeview.invisibleRootItem()
2. ルートノードの子ノードの数を取得する:
child_count = root.childCount()
子ノードを再帰的に削除する:
for i in range(child_count):
child = root.child(i)
root.removeChild(child)
完全なコードは次のようになります:
root = treeview.invisibleRootItem() child_count = root.childCount() for i in range(child_count):
child = root.child(i)
root.removeChild(child)