[PyQt] QGraphicsScene problem
Andrew Magee
amagee at gmail.com
Mon Jul 2 06:01:29 BST 2007
Hello all. I've been playing around with pyqt 4 for a while but I've
run into a problem retrieving items from a QGraphicsScene's items
collection; the items returned seem to be garbage and cause the python
interpreter to segfault when I try to execute methods from them.
I can't seem to find any workaround that will let me find out what
item in the scene was clicked from a mouse event - does anyone have
any ideas about that?
Here's the simplest program I could come up with to reproduce the
problem. I'm guessing this is a bug in pyqt but I don't really know
much about it.
Thanks.
------
import sys
from PyQt4 import QtCore, QtGui
class CalendarScene(QtGui.QGraphicsScene):
def __init__(self, parent = None):
QtGui.QGraphicsScene.__init__(self, parent)
a = QtGui.QGraphicsTextItem()
a.setPlainText('a')
a.setPos(0, 0)
self.addItem(a)
b = QtGui.QGraphicsTextItem()
b.setPlainText('b')
b.setPos(50, 0)
self.addItem(b)
# prints <class 'PyQt4.QtGui.QGraphicsTextItem'> as expected
print self.items()[0].__class__
# segfaults
print self.items()[0].toPlainText()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = QtGui.QGraphicsView()
scene = CalendarScene()
window.setScene(scene)
window.show()
sys.exit(app.exec_())
------
More information about the PyQt
mailing list