On Thu, 29 Aug 2013 14:58:07 +0000, Yann Le Hir <yann.le-...@arteris.com> wrote: > Hi, > > I'm having an issue with QGraphicsItem::itemChange. > > Here is the test program : > > import PyQt5.Qt as qt > > class Node( qt.QGraphicsRectItem ) : > def __init__( self , sector ) : > super( Node , self ).__init__( sector ) > > def itemChange( self , change , v ) : > res = super( Node , self ).itemChange( change , v ) > print "itemChange return value : ",res > return res > > b = qt.QGraphicsLineItem() > c = qt.QGraphicsLineItem() > a = Node(b) > print a.parentItem(),b > a.setParentItem(c) > print a.parentItem(), c > > > I get this output : > <PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f194> > <PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f194> > itemChange return value : <PyQt5.QtWidgets.QGraphicsLineItem object at > 0x8f9f1dc> > itemChange return value : <PyQt5.QtWidgets.QGraphicsLineItem object at > 0x8f9f1dc> > None <PyQt5.QtWidgets.QGraphicsLineItem object at 0x8f9f1dc> > > If I remove itemChange, I get this output : > <PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e6814c> > <PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e6814c> > <PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e68194> > <PyQt5.QtWidgets.QGraphicsLineItem object at 0xf2e68194> > > I'm using PyQt-5.0, Sip 4.14.7 and Qt 5.1.0 > I tried with PyQt-5.0.1, sip 4.15.1 and Qt 5.1.0 without change. > > I digged into this, basically when setParentItem is called itemChange is > called on this item and use the return value of itemChange to set the > parent. > In C itemChange returns a QVariant, which must be casted as a > QGraphicsItem to be set as a parent. > This took me to the Chimera::parse_py_type function. Apparently, someone > (QT?) registers QGraphicsItem as a QMetaType, but not QGraphicsLineItem. > > If I replace : > _metatype = QMetaType::type(_name.constData()); > By : > if(strcmp(_name.constData(),"QGraphicsLineItem*")==0) > _metatype = QMetaType::type("QGraphicsItem*"); > else > _metatype = QMetaType::type(_name.constData()); > > (I know how bad this is, but it's for demonstration purpose.) > > The output of the test program is then : > <PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba194> > <PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba194> > itemChange return value : <PyQt5.QtWidgets.QGraphicsLineItem object at > 0x89ba1dc> > itemChange return value : <PyQt5.QtWidgets.QGraphicsLineItem object at > 0x89ba1dc> > <PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc> > <PyQt5.QtWidgets.QGraphicsLineItem object at 0x89ba1dc> > > Any ideas on how to fix this properly ?
Should be fixed in tonight's PyQt5 snapshot. Phil _______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt