MousePressEvent捕捉信号不必要的PyQt4

2024-09-28 20:17:37 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我有一个QraphicsScene和一个QGraphicsPolygonItem,我把它标记为可移动的。我还覆盖了MousePressEvent。我的代码片段tll现在。在

def mousePressEvent(self , e):
    self.endx = e.x()
    self.endy = e.y()
    if self.sender == 1:
        self.LineChange(self.endx , self.endy)

#...

def CreateFun(self):
    poly = QtGui.QPolygonF([QtCore.QPointF(100 , 100) , QtCore.QPointF(100 , 200) , QtCore.QPointF(200 , 200)])
    self.polygon = QtGui.QGraphicsPolygonItem(poly)
    self.scene.addItem(self.polygon)
    self.polygon.setFlag(QtGui.QGraphicsItem.ItemIsMovable)

但是多边形没有移动。当我把MousePressEvent注释掉的时候,它移动得很好。我猜是我的口香糖抓到之前。在

上面的函数都是继承自QtGui.QGraphicsView视图. 有什么建议吗?在


Tags: 代码标记selfdefpolypolygonqtguitll
1条回答
网友
1楼 · 发布于 2024-09-28 20:17:37

您应该调用mousePressEvent的基本实现。QGraphicsView通常将这些单击传递给可能使用它们的其他项。如果不调用基本实现,则基本上是在“捕获”单击。在

修改您的mousePressEvent如下:

def mousePressEvent(self , e):
    self.endx = e.x()
    self.endy = e.y()
    if self.sender == 1:
        self.LineChange(self.endx , self.endy)
    # let the base implementation do its thing
    super(Palette, self).mousePressEvent(e)

相关问题 更多 >