每当我双击小部件时,我想获取 pyqtgraph 小部件上的鼠标光标坐标并将它们发送到函数。我查找了如何做并可以找到一些类似的问题,但我仍然无法获得正确的坐标。
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.dockarea import *
from PyQt5.QtGui import *
from PyQt5.QAxContainer import *
from PyQt5.QtCore import *
def on_double_click_out(event):
pos = event
print('clicked', pos)
class Plotter():
def __init__(self):
pg.setConfigOption('background', 'w')
pg.setConfigOption('foreground', 'k')
self.win = QtGui.QMainWindow()
self.area = DockArea()
self.win.setCentralWidget(self.area)
self.win.resize(1000,500)
self.win.setWindowTitle('pyqtgraph example: dockarea')
self.dock_TR = Dock("TR", size=(300,10))
self.dock_TR.hideTitleBar()
self.area.addDock(self.dock_TR)
self.widgetTR = pg.PlotWidget()
self.widgetTR.showGrid(x=True, y=True, alpha=0.3)
self.dock_TR.addWidget(self.widgetTR)
self.win.show()
p = Plotter()
proxy = pg.SignalProxy(p.widgetTR.scene().sigMouseClicked, rateLimit=60, slot=on_double_click_out)
当我在 widgetTR 上单击(不是双击)时,我得到一些坐标,但它们与 x、y 轴无关。例如,当我单击小部件的 (1, 1) 时,结果是clicked (<MouseClickEvent (573,-259) button=1>,)我还想知道是否可以通过双击来完成此操作。
慕码人8056858
相关分类