[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.



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.setPos(0, 0)

    b = QtGui.QGraphicsTextItem()
    b.setPos(50, 0)

    # 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()


More information about the PyQt mailing list