Hi,
i am having problems wrapping my head around on how to modify a model of a
Qtree i have set up. my model consists out of a few children under root and
each child has some children of it's own. to start of with i followed the
simpleTreeModel example and got to the stage where my model gets correctly
displayed. what i would like to do now is with a button trigger an update to
the model and only displaying one of the items for example.

here are part of my codes. but really it's based on the simpleTreeExample

class TreeModel(QtCore.QAbstractItemModel):
    def __init__(self, data, parent=None):
        QtCore.QAbstractItemModel.__init__(self, parent)

        rootData = []
        rootData.append(QtCore.QVariant("Object"))
        rootData.append(QtCore.QVariant("File 1"))
        rootData.append(QtCore.QVariant("File 2"))
        self.rootItem = TreeItem(rootData)
        self.setupModelData(data, self.rootItem)

..............
.
.
.

def data(self, index, role):
        if not index.isValid():
            return QtCore.QVariant()

        if role != QtCore.Qt.DisplayRole:
            return QtCore.QVariant()

        item = index.internalPointer()

        return QtCore.QVariant(item.data(index.column()))

..
..
..
def setupModelData(self, data, parent):
        parents = []
        parents.append(parent)
        for object in sorted(data.keys()):
            columnData = []
            columnData.append(object)
            columnData.append(data[object][0])
            columnData.append(data[object][1])

            adbItem = TreeItem(columnData, parents[-1])
            parents[-1].appendChild(adbItem)
            for each in data[object][2][0].keys():
                columnData = []
                columnData.append(each)
                columnData.append(data[object][2][0][each])
                columnData.append(data[object][2][1][each])
                adbItem.appendChild(TreeItem(columnData, adbItem))

thanks in advance

sven
_______________________________________________
PyQt mailing list    [email protected]
http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Reply via email to