如何在GUI应用程序中的PyQtGraph中等待鼠标交互时返回值

时间:2019-09-10 19:57:09

标签: python pyqtgraph pyside2

我想在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
    """???"""

0 个答案:

没有答案