[PyQt] Problem connecting signal and slot between a QGraphicsItem and QGraphicsScene

Phil Thompson phil at riverbankcomputing.com
Wed Dec 23 22:33:36 GMT 2009


On Wed, 23 Dec 2009 11:17:14 -0800 (PST), dizou <di_zou at yahoo.com> wrote:
> I have a class that inherits the QGraphicsItem and QObject. In the
> mousePressEvent() function, it emits a signal. I want to connect this
> signal
> with a function in the QGraphicsItem's QGraphicsScene. This is what I
have:
> 
> class DisplayItem(QGraphicsItem, QObject):
>     def __init__(self):
>         QGraphicsItem.__init__(self)
>         QObject.__init__(self)
>     def mousePressEvent(self, event):
>         self.update()
>         self.emit(SIGNAL("updateItemSelected()"))
>         QGraphicsItem.mousePressEvent(self, event)
> 
> class DisplayScene(QGraphicsScene):
>     def __init__(self, parent):
>         QGraphicsScene.__init__(self, parent)
>     def DisplayChildren(self, item, graphViews, x, y):
>         dispItem = item.GetDisplayItem() #This returns a DisplayItem()
> object
>         dispItem.setGraphView(graphViews[0])
>         dispItem.setPos(x, y)
>         
>         self.connect(dispItem, SIGNAL("updateItemSelected()"),
> self.ItemSelected)
>         self.addItem(dispItem)
> 
> When I run this and call the DisplayScene.DisplayChildren() function, I
get
> this error:
> self.connect(dispItem, SIGNAL("updateItemSelected()"), self.ItemSelected)
> SystemError: error return without exception set

PyQt doesn't support sub-classing from two wrapped classes. PyQt v4.7 will
raise an exception if you try.

If you are using Qt v4.6 then sub-class from QGraphicsObject instead.

Phil


More information about the PyQt mailing list