[PyQt] changing model for QTree
Sven Pohle
spohle at gmail.com
Wed Jan 28 05:54:53 GMT 2009
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090128/79eca48c/attachment-0001.html
More information about the PyQt
mailing list