如何解决从pyqtgraph返回鼠标单击坐标作为列表
我对pyqtgraph相当陌生,并且已经学习python一段时间了。我正在尝试从pyqtgraph plotitem获取鼠标单击坐标。 这就是我到目前为止所拥有的。
class CrossHair():
def __init__(self,win,row=0,col=0):
self.label = pg.LabelItem(justify='right')
self.p1 = win.getItem(row=row,col=col)
self.p1.setAutoVisible(x=True,y=True)
win.addItem(self.label,row=row,col=col)
self.vLine = pg.InfiniteLine(angle=90,movable=False)
self.hLine = pg.InfiniteLine(angle=0,movable=False)
self.vb = self.p1.vb
self.p1.addItem(self.vLine,ignoreBounds=True)
self.p1.addItem(self.hLine,ignoreBounds=True)
self.proxy = pg.SignalProxy(self.p1.scene().sigMouseMoved,rateLimit=60,slot=self.mouseMoved)
self.p1.scene().sigMouseClicked.connect(self.mouseClicked)
#self.p1.scene().sigMouseMoved.connect(self.mouseMoved)
def mouseMoved(self,evt):
pos = evt[0] ## using signal proxy turns original arguments into a tuple
if self.p1.sceneBoundingRect().contains(pos):
mousePoint = self.vb.mapScenetoView(pos)
self.label.setText("<span style='font-size: 10pt'>x=%0.1f,<span style='color: red'>y=%0.1f</span>"%(mousePoint.x(),mousePoint.y()))
self.vLine.setPos(mousePoint.x())
self.hLine.setPos(mousePoint.y())
def mouseClicked(self,event):
global mouse_coordinates
mouse_coordinates=[]
pos = event.scenePos()
mousePoint = self.vb.mapScenetoView(pos)
mouse_coordinates = [mousePoint.x(),mousePoint.y()]
return mouse_coordinates
#self.sigMouseClicked.disconnect()
我想定义一个函数get_points(win)
,该函数将使用当前的pyqtgraph窗口,绘制一个十字准线,并且每当我单击时,都将返回鼠标单击坐标的列表。单击一次后,除非再次调用该函数,否则我不希望它再注册任何坐标。
我写了这样的东西,但是没用:
def get_points(win):
ch = CrossHair(win)
ch.p1.scene().sigMouseClicked.connect(ch.mouseClicked)
任何帮助或建议,我们将不胜感激!
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。