Delete QTreeWidgetItem in PyQt?

后端 未结 2 687
灰色年华
灰色年华 2021-02-05 17:06

I\'m finding it frustratingly hard to find a simple way to delete my selected QTreeWidgetItem.

My patchwork method involves setting the tree\'s current sele

2条回答
  •  猫巷女王i
    2021-02-05 18:01

    The QTreeWidget class has an invisibleRootItem() function which allows for a somewhat neater approach:

    root = tree.invisibleRootItem()
    for item in tree.selectedItems():
        (item.parent() or root).removeChild(item)
    

提交回复
热议问题