I'd like to use a InfiniteLine in in pyqtgraph that moves with the mouse moving. Upon left-clicking the function shall return the xposition. I am able to retrieve the x-value on left-clicking and moving the InfiniteLine with the mouse movement. However I am stucked at simply returning the x position. I'd like to wait for the left click, as I want to repeat this procedure multiple times.
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
"""???"""