I am trying to recreate the mouse movement slot from the "Crosshair / Mouse Interaction" example using addViewBox instead of addPlot, but it doesn't seem to be mapping the position -> line correctly. Has anyone tried this?
import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.Point import Point
app = QtGui.QApplication([])
win = pg.GraphicsWindow()
win.setWindowTitle('pyqtgraph example: crosshair')
label = pg.LabelItem('NICK', justify='center')
win.addItem(label)
p1 = win.addViewBox(row=1, col=0)
image = pg.ImageItem(np.random.randn(50,50))
p1.addItem(image)
vLine = pg.InfiniteLine(angle=90, movable=False)
hLine = pg.InfiniteLine(angle=0, movable=False)
p1.addItem(vLine, ignoreBounds=True)
p1.addItem(hLine, ignoreBounds=True)
def mouseMoved(evt):
pos = evt[0]
if p1.sceneBoundingRect().contains(pos):
mousePoint = p1.mapSceneToView(pos)
vLine.setPos(pos.x())
hLine.setPos(pos.y())
proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60, slot=mouseMoved)