Delete QTreeWidgetItem in PyQt?

后端 未结 2 686
灰色年华
灰色年华 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条回答
  • 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)
    
    0 讨论(0)
  • 2021-02-05 18:05

    PyQt4 uses sip to generate the python bindings for Qt classes, so you can delete the C++ object explicitly through the sip python API:

    import sip
    ...
    sip.delete(current)
    

    The binding generator for PySide, shiboken, has a similar module.

    0 讨论(0)
提交回复
热议问题