[PyQt] QGraphicsScene problem
phil at riverbankcomputing.co.uk
Mon Jul 2 09:29:49 BST 2007
On Monday 02 July 2007 6:01 am, Andrew Magee wrote:
> 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().__class__
> # segfaults
> print self.items().toPlainText()
> if __name__ == "__main__":
> app = QtGui.QApplication(sys.argv)
> window = QtGui.QGraphicsView()
> scene = CalendarScene()
Works fine for me.
More information about the PyQt