PyQt - XML to QTreeWidget

前端 未结 2 1971
無奈伤痛
無奈伤痛 2020-12-10 10:17

I\'m trying to make a basic XML story maker in PyQt. So far I\'ve been able to figure out everything my self, but I\'ve run into a bit of a snag. I can\'t figure out how to

2条回答
  •  被撕碎了的回忆
    2020-12-10 10:26

    You'll need to write something yourself to pull in the information from the XML file (hint: use a python XML parser like ElementTree). This code will build a tree widget with the rows (and subrows) filled out from data.

    class Tree(QtGui.QTreeWidget):
    
        def __init__(self, parent):
            # maybe init your data here too
            super(Tree, self).__init__(parent)
    
        def populate(self, data):
            # populate the tree with QTreeWidgetItem items
            for row in data:
                # is attached to the root (parent) widget
                rowItem = QtGui.QTreeWidgetItem(parent)
                rowItem.setText(0, row)
                for subRow in row:
                     # is attached to the current row (rowItem) widget
                     subRowItem = QtGui.QTreeWidgetItem(rowItem)
                     subRowItem.setText(0, subRow)
    

提交回复
热议问题