我想在pyqtgraph中使用随鼠标移动而移动的InfiniteLine。左键单击时,函数应返回xposition。我能够通过单击鼠标左键并移动InfiniteLine来检索x值。但是,我坚持只返回x位置。我想等待单击鼠标左键,因为我想多次重复此过程。
def addVerticalLineAndGetXOnClick(self):
def changePosVertLine(event):
if self.sceneBoundingRect().contains(event):
mousePoint = self.plotItem.vb.mapSceneToView(event)
line.setPos(mousePoint.x())
def onMouseClick(event):
if event.button() == 1:
self.removeItem(line)
self.scene().sigMouseClicked.disconnect()
self.setMouseTracking(False)
mousePoint = self.plotItem.vb.mapSceneToView(event.scenePos())
self.xPos.emit(mousePoint.x())
penLin = mkPen(color = '#000000', width = 1)
line = LRI(0.,pen = penLin, name= 'singleLineToGetXPos' )
self.addItem(line)
self.setMouseTracking(True)
self.scene().sigMouseMoved.connect(changePosVertLine)
self.scene().sigMouseClicked.connect(onMouseClick)
#wait to return after mouse click and return
"""???"""