[PyQt] Converting C++ to Python

Rajeev J Sebastian rajeev.sebastian at gmail.com
Thu Sep 20 17:29:14 BST 2007


Hello Phil,

On 9/20/07, Phil Thompson <phil at riverbankcomputing.co.uk> wrote:
> > The problem is that the first element *should* actually be a
> > <__main__.DiagramTextItem> rather than a QGraphicsItem.
> > (DiagramTextItem is a subclass of QGraphicsTextItem).
> >
> > In other words, for some reason, python subclasses of
> > QGraphicsTextItem arent recognized correctly when the same are
> > returned from C++.
> No.
>
> Is your DiagramTextItem reimplementing type()?
>
> I'm guessing it is. In which case PyQt isn't recognising it and falling back
> to QGraphicsItem. If you don't reimplement type() it should at least
> recognise it as a QGraphicsTextItem. If this isn't good enough then you will
> have to keep a reference (probably in a list) of each DiagramTextItem
> instance so that items() will see that the C++ addresses it is getting back
> to Qt correspond to existing Python objects (of the correct type).

Thank you for your quick response.

Yes, in fact I am reimplementing type() in DiagramTextItem.

I would like to point out that DiagramItem and Arrow are both
subclasses of QGraphicsItem (QGraphicsPolygonItem and
QGraphicsLineItem respectively), and both also reimplement type().
However, PyQt4 seems to recognize them properly and returns objects
with the right type.

Hence, my question on whether the special aspect of QGraphicsTextItem
is affecting this code.

I tried to do what you had suggested, i.e., store references to these
objects. However, that doesnt work as expected. I still get
QGraphicsItem objects.

Regards
Rajeev J Sebastian


More information about the PyQt mailing list