[PyQt] createIndex() in treemodels and pyqt-book
Knacktus
knacktus at googlemail.com
Fri Aug 27 07:40:06 BST 2010
Hello everyone,
I'm a bit confused about the third argument of the createIndex() method.
The Qt class documentation simply says it's an internal pointer. Then,
the PyQt-Book "Rapid GUI Programming ..." says index have a row, column
and a parent. So I thought the pointer must be a pointer to the parent
index. That's also what additional Qt documentation on the model-view
framework is saying:
http://doc.qt.nokia.com/4.6/model-view-model.html
(paragraph "Parents of Items")
But on the other hand, the Qt doc says about
ModelIndex::internalPointer, that it's an association with the internal
data structure, so it wouldn't be a pointer to another model index.
Also, when I look at examples in the pyqt-Book it looks like parent is
the parent in the underlaying data structure.
code from the example of chapter 16, treeoftable.py:
####################################################
def index(self, row, column, parent):
assert self.root
branch = self.nodeFromIndex(parent)
assert branch is not None
return self.createIndex(row, column,
branch.childAtRow(row))
def nodeFromIndex(self, index):
return (index.internalPointer()
if index.isValid() else self.root)
So, what's the pointer pointing to?
- a QModelIndex of the the parent in the underlying data structure
- a reference to the corresponding item itself in the underlying data
structure
- a reference to the corresponding parent of the item in the underlying
data structure
Thanks in advance and cheers,
Jan
More information about the PyQt
mailing list