PyQt Tree Widget, adding check boxes for dynamic removal

前端 未结 4 745
一生所求
一生所求 2020-12-28 11:21

I am attempting to create a tree widget that will essentially allow the user to view various breakdowns of data and have the option to delete certain items. In order to do t

4条回答
  •  旧巷少年郎
    2020-12-28 11:31

    This is not an answer to your question, rather how to use the checkboxes once you have them. I used the example above from the answer marked as correct. It worked, but then when I tried to find how to know which checkboxes were marked, and I had a lot of issues. After a lot of searching I found a solution that worked for me, as I see there is no a lot of doc, so I want to leave a record for the future. Just to mention I used several solutions as invisibleRootItem in order to find the children of the parent but that didn't work.

    I ended up using the class QTreeWidgetItemIterator with a flag QtGui.QTreeWidgetItemIterator.Checked in order to retreive the text of the checkboxes marked, and with that, I can continue working.

    def vrfs_selected(self):
        iterator = QtGui.QTreeWidgetItemIterator(self.tree, QtGui.QTreeWidgetItemIterator.Checked)
        while iterator.value():
            item = iterator.value()
            print (item.text(0))    
            iterator += 1
    

    the link to the documentation http://ftp.ics.uci.edu/pub/centos0/ics-custom-build/BUILD/PyQt-x11-gpl-4.7.2/doc/html/qtreewidgetitemiterator.html and an example https://riverbankcomputing.com/pipermail/pyqt/2014-May/034315.html

提交回复
热议问题