gpt4 book ai didi

python - MousePressEvent 捕获不必要的信号 - PyQt4

转载 作者:太空宇宙 更新时间:2023-11-03 19:07:03 24 4
gpt4 key购买 nike

所以我有一个带有 QGraphicsPolygonItem 的 QraphicsScene ,我将其标记为可移动。我还重写了 MousePressEvent。我的代码片段现在已经出来了。

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 时,它移动得很好。我的猜测是 MousePressEvent 在 PolygonItem 之前捕获它。

而上述函数均来自于继承自QtGui.QGraphicsView的类。有什么建议吗?

最佳答案

您应该调用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)

关于python - MousePressEvent 捕获不必要的信号 - PyQt4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14453799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com