我一直在努力重新实现一个QGraphicsItem
,但是当单击该项时,我尝试用该类运行的其他函数只会影响第一次单击的实例。我的问题是,如何绕过这个问题,只影响显式单击的实例?你知道吗
我的班级如下:
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!?!?
这是通过调用原始类函数而不是完全重写它来修复的。你知道吗
在mousePressEvent中:
相关问题 更多 >
编程相关推荐