[PyQt] Using QModelIndex.internalPointer

David Boddie david at boddie.org.uk
Sat Dec 5 17:06:23 GMT 2009


On Fri, 4 Dec 2009 08:25:30 -0800 (PST), Bakuriu wrote:

> I'm trying to create a model so I inheritad QAbstractItemModel and
> implemented the necessary methods.
> Now i'm stuck at implementing the "parent" method.

[...]

> The problem is that when i call the QModelIndex.internalPointer method it
> returns the class "Word" and not an instance of that class.

This sounds like a bug, but it depends on what you pass to the model's
createIndex() method in your index() implementation, as you say later...

> Therefore i cannot retrieve the parent index(my wrapper class also has got
> methods which returns the index position of a word in the tree
> representation using a tuple)
>
> I read the documentation but it simply says that it returns a void*
> pointer(in C++).
> Anyone knows how to retrieve the exact data from a QModelIndex?

The internalPointer() method returns a Python object in PyQt, so what you
are doing should work.

> Ps:
> In the index method i call createIndex passing the right row and column and
> an instance of the object, not the class...

Then this would indicate that there may be a bug with the createIndex()
wrapper in PyQt, though it would be difficult to know exactly what the
cause is without a test case or minimal example that demonstrates the
problem.

Which versions of SIP and PyQt are you using?

David


More information about the PyQt mailing list