I've been working on reimplementing a QGraphicsItem
, but when the item is clicked, further functions I try to run with that class only affect the instance that was first clicked. My question is, how do I get around this, and only affect the instance that is explicitly clicked?
My class is as follows:
class PrefabPoly(QGraphicsPolygonItem):
def __init__(self, points, pen, brush, graphicsItem, parent=None):
super(PrefabPoly, self).__init__(QPolygon(points), graphicsItem, parent.scene)
self.setPen(pen)
self.setBrush(brush)
self.setCursor(Qt.PointingHandCursor)
self.parent = parent
def mousePressEvent(self, e):
print("press")
if isinstance(self.parent, CreatePrefabGridWidget):
self.setBrush(self.parent.cur_color)
#The brush is only changed for the item that was clicked first!?!?
This was fixed by calling the original class function instead of totally overriding it.
In the mousePressEvent: