
Originally Posted by
d_stranz
The third parameter is also defined as a void * pointer, which in reality means it can contain anything that will fit into the size of a pointer (usually the same size as an unsigned long). In Python, you could possibly use this to store the index into a list of objects, for example. The implementation of PySide might even coerce a Python object reference into a pointer "under the hood" so you may be able to store a Python object reference in it.
But as anda_skoa says, it is rare that you need to use this third parameter unless you are implementing a tree or a proxy model where it would be difficult to navigate the model otherwise.
Very useful stuff. I am indeed building a tree model by subclassing QAbstractItemModel. I was looking at the implementation of QAbstractTableModel just to check that I understood what I was doing.
Indeed, in Python, the third input to createIndex is actually just any old Python object, of any type. Typically we just feed in the data item itself to become referred to by the index (e.g., in simpletreemodel example, we give it a TreeItem type directly as the parameter, no pointers or anything like that, which don't exist in Python).
I have finally started to sort out these issues in a couple of threads over at stack overflow:
http://stackoverflow.com/questions/2...qt-model-items
http://stackoverflow.com/questions/2...ject-in-python
Though I a admit I am still a bit puzzled by the following:
: r(other.r), c(other.c), p(other.p), m(other.m) {}
inline QModelIndex(const QModelIndex &other)
: r(other.r), c(other.c), p(other.p), m(other.m) {}
To copy to clipboard, switch view to plain text mode
As I said, I am no c++ coder, so this just seems foreign to me. It seems to be creating a QModelIndex out of these r (row), c (column), p (pointer to the data item), and m (I assume the model that it got the index from). But I don't where where it is creating the .row(), .column(), .getInternalPointer(), .model(), and other methods associated with an index. Where is that behavior defined? I can see how it would be fairly easy to get those methods based on the parameters the function is receiving, but would like to see in the source how it all works...
Bookmarks