0
QGraphicsItem
을 다시 구현하고 있지만 항목을 클릭하면 해당 클래스로 실행하려고하는 추가 기능은 처음 클릭 한 인스턴스에만 영향을줍니다. 내 질문은이 문제를 어떻게 해결할 수 있으며 명시 적으로 클릭 한 인스턴스에만 영향을 미칩니 까?QGraphicsScene에서 mousePressEvent가 예상대로 작동하지 않습니다
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!?!?