所以我有一个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视图. 有什么建议吗?在
您应该调用
mousePressEvent
的基本实现。QGraphicsView
通常将这些单击传递给可能使用它们的其他项。如果不调用基本实现,则基本上是在“捕获”单击。在修改您的
mousePressEvent
如下:相关问题 更多 >
编程相关推荐