[PyQt] Converting C++ to Python
phil at riverbankcomputing.co.uk
Thu Sep 20 16:59:35 BST 2007
On Thursday 20 September 2007, Rajeev J Sebastian wrote:
> Hi Phil,
> Thanks for the response, but I would like some clarification:
> I should do
> if (self.textInteractionFlags() & QtCore.Qt.TextEditable):
> ... do some stuff ...
> is that correct ?
Yes, although you don't need the outer parenthesis.
> Also, I have another question.
> In the diagramscene app, in the QGraphicsScene subclass, I do the
> for item in self.items():
> print item
> Which prints the following:
> <PyQt4.QtGui.QGraphicsItem object at 0xa7a7a0ac>
> <__main__.DiagramItem object at 0xa7a7acac>
> <__main__.DiagramItem object at 0xa7a7abac>
> <__main__.Arrow object at 0xa7a7ad2c>
> 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++.
> I can see that QGraphicsTextItem gets some special treatment in the
> .sip files ... would this affect its use ?
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).
More information about the PyQt