[PyQt] PyQt5, QGraphicsObject, Selection Indicator, and Multiple Inheritance

Alan Ezust alan.ezust at gmail.com
Fri Feb 27 16:30:40 GMT 2015


I had a QGraphicsRectItem before that I needed to add signals to.

I had trouble getting multiple inheritance to work between QGraphicsObject
and QGraphicsRectItem. As soon as I tried to call self.setBrush(), the
interpreter crashed, and I am not able to see any kind of error message
that indicates what might be the problem.


class PartFrame2dItem(QGraphicsObject, QGraphicsRectItem):
def __init__(self):

QGraphicsObject.__init__(self)
QGraphicsRectItem.__init__(self)
# A child rectangle item
#self._rect_item = QGraphicsRectItem(self)
#self._rect_item.setZValue(-1)
self.setZValue(-1)
#self._rect_item.setBrush(QBrush(QColor(235,235,235)))
self.setBrush(QBrush(QColor(235,235,235)))

Is there something wrong with my __init__?
Why would it crash like that on the setBrush() ?

So I redesigned it so that the QGraphicsObject creates a child
QGraphicsRectItem. But now, when I select the item from the view, I don't
see any dotted line selection indicator around the thing.

Am I supposed to override and delegate some event handler or method to the
from the QGraphicsObject to the QGraphicsRectItem in order to see that
dotted line selection effect?

Thanks for any insights you might have.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20150227/716f0911/attachment.html>


More information about the PyQt mailing list