[PyQt] Subclass of QGraphicsObject does not have the correct class name listed in QGraphicsScene.items()
Selim Tuvi
Selim.Tuvi at pdi.dreamworks.com
Thu May 19 22:42:47 BST 2011
The code below outputs:
[<__main__.Edge object at 0x2aaab0395830>, <PyQt4.QtGui.QGraphicsItem
object at 0x2aaab03958c0>]
which lists the Node instance as having the class QGraphicsItem when it
should say <__main__.Node object at ...>.
Tested on (Qt 4.7.2, PyQt 4.8.3) and (Qt 4.6.1, PyQt 4.7.2)
Thanks
-Selim
from PyQt4 import QtGui, QtCore
class Node(QtGui.QGraphicsObject):
def __init__(self):
QtGui.QGraphicsObject.__init__(self)
def paint(self, painter, option, widget):
pass
def boundingRect(self):
return QtCore.QRectF()
class Edge(QtGui.QGraphicsItem):
def __init__(self):
QtGui.QGraphicsItem.__init__(self)
def paint(self, painter, option, widget):
pass
def boundingRect(self):
return QtCore.QRectF()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
print QtCore.QT_VERSION_STR, QtCore.PYQT_VERSION_STR
view = QtGui.QGraphicsView()
scene = QtGui.QGraphicsScene()
view.setScene(scene)
scene.addItem(Node())
scene.addItem(Edge())
print scene.items()
view.show()
sys.exit(app.exec_())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Selim_Tuvi.vcf
Type: text/x-vcard
Size: 375 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20110519/cf10cd4b/attachment.vcf>
More information about the PyQt
mailing list