Python 如何在QGraphicsView中获取鼠标释放坐标
嗨,我是Qt和pyside的新手。我正在尝试获取QGraphicsView实例中鼠标的坐标。我试图重新实现我的mouseReleaseEvent,但不知道如何实际使用这个重新实现的函数 在主窗口类中:Python 如何在QGraphicsView中获取鼠标释放坐标,python,qt,pyside,Python,Qt,Pyside,嗨,我是Qt和pyside的新手。我正在尝试获取QGraphicsView实例中鼠标的坐标。我试图重新实现我的mouseReleaseEvent,但不知道如何实际使用这个重新实现的函数 在主窗口类中: self.tScn = QtGui.QGraphicsScene() self.graphicsView_2 = QtGui.QGraphicsView(self.centralwidget, self.tScn) 在MainConsumer类中(从MainWindow派生: def point
self.tScn = QtGui.QGraphicsScene()
self.graphicsView_2 = QtGui.QGraphicsView(self.centralwidget, self.tScn)
在MainConsumer类中(从MainWindow派生:
def pointSelection(self):
pos = self.tScn.mouseReleaseEvent(QMouseEvent)
print(pos)
def mouseReleaseEvent(self, QMouseEvent):
pos = QMouseEvent.lastScenePos()
print(pos)
return pos
python给了我以下警告:
AttributeError:'PySide.QtGui.QMouseEvent'对象没有属性'lastScenePos
'
我尝试了两种不同的顺序和结构,但都不起作用,现在我真的被PySide.QtGui.qgraphicscene.mouseReleaseEvent(event)
,PySide.QtGui.qgraphicscenemouseevent.lastScenePos()
,类PySide.QtGui.qgraphicscenemouseevent([type=None])之间的关系搞糊涂了
和QtCore.QEvent.graphicscenemouseRelease
有人能帮我吗
谢谢!创建一个从QGraphicscene继承的类,并具有如下信号
class MyGraphicsScene(QtGui.QGraphicsScene):
signalMousePos = QtCore.pyqtSignal(QtCore.QPointF)
def __init__(self, parent):
super(MyGraphicsScene, self).__init__(parent)
然后重写这个新类中的mouseRelease事件
def mouseReleaseEvent(QGraphicsSceneMouseEvent):
pos = QGrapihcsSceneMouseEvent.lastScenePos()
self.signalMousePos.emit(pos)
然后在MainConsumer类中替换
self.tScn = QtGui.QGraphicsScene()
与
点选择变为
def pointSelection(self, pos)
#Whatever you want to do with the position coordinates
主消费者中的mouseReleaseEvent不再需要了非常感谢!!哈哈,就在11分钟前,我自己想出来了,回来回答我自己的问题,但是你的解释更加条理清晰,再次感谢!
def pointSelection(self, pos)
#Whatever you want to do with the position coordinates