I'm attempting to develop a GUI that allows for tracking mouse coordinates in the PlotWidget, and displaying in a label elsewhere in the main window. I have attempted several times to emulate the crosshair example in the pyqtgraph documentation, but have not been able to get it to agree to do this. A part of the difficulty is that I am unable to understand how to access the mouse tracking I can enable in the QtDesigner.
I attempted to use the:
proxy = pg.SignalProxy(Plotted.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)
Plotted.scene().sigMouseMoved.connect(mouseMoved)
However, I do not quite understand what allows for this to "update" in real time, nor at what level I should have this statement. Should the
def mouseMoved(evt):
pos = evt[0]
if Plotted.sceneBoundingRect().contains(pos):
mousePoint = vb.mapSceneToView(pos)
index = int(mousePoint.x())
if index > 0 and index < len(x):
mousecoordinatesdisplay.setText("<span style='font-size: 12pt'>x=%0.1f, <span style='color: red'>y1=%0.1f</span>" % (mousePoint.x(), y[index], data2[index]))
vLine.setPos(mousePoint.x())
hLine.setPos(mousePoint.y())
part of the code be in the Ui_MainWindow class, or outside of it?
SignalProxyshould already be equivalent to... .sigMouseMoved.connect(...). Also the mouse tracking should be happening in the pyqtgraph plot widget. I don't think any relation exists with other options you are activating on QtDesigner. The way this works is likely the way any SIGNAL/SLOT works. SignalProxy sends a signal every time the mouse is moved and runs whatever method you implemented for the connection. This isn't real time, it should only be launched when the mouse is moved. - armatita