Never mind.. Clearly there is a bug above in my code using 'pos' instead of
'mousePoint' but regardless I got it to work with the following for others
to reference:
import numpy as np
import pyqtgraph as pg
from pyqtgraph.Qt import QtGui, QtCore
from pyqtgraph.Point import Point
#app = QtGui.QApplication([])
pg.mkQApp()
win = pg.GraphicsLayoutWidget()
win.show()
win.setWindowTitle('pyqtgraph example: crosshair')
p1 = win.addViewBox(row=1, col=0)
image = pg.ImageItem()
p1.addItem(image)
image.setImage(np.random.randn(100,100))
vLine = pg.InfiniteLine(angle=90, movable=False)
hLine = pg.InfiniteLine(angle=0, movable=False)
p1.addItem(vLine, ignoreBounds=True)
p1.addItem(hLine, ignoreBounds=True)
#vb = p1.vb
def mouseMoved(evt):
pos = evt[0]
if p1.sceneBoundingRect().contains(pos):
mousePoint = p1.mapSceneToView(pos)
vLine.setPos(mousePoint.x())
hLine.setPos(mousePoint.y())
proxy = pg.SignalProxy(p1.scene().sigMouseMoved, rateLimit=60,
slot=mouseMoved)
#p1.scene().sigMouseMoved.connect(mouseMoved)
## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()
On Saturday, February 25, 2017 at 5:46:12 PM UTC-5, [email protected]
wrote:
>
> 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?
>
> Here is the code
>
> ```
> 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)
> ```
>
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/075fb183-d017-4a97-86f2-611b625a22c3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.