Mouse move events for ImageView

264 views
Skip to first unread message

Aaron

unread,
Sep 2, 2015, 1:09:32 AM9/2/15
to pyqtgraph
Hi,

I am trying to capture when the mouse moves over an ImageView to update my UI.

I tried to hook the events directly on the view:

def move(event):
print('test')


imv = ImageView()
imv.setMouseTracking(True)
imv.mouseMoveEvent = move 

This does not generate any events.

I also tried subclassing ImageView with similar results:
class MyView(ImageView):
def __init__(self, parent=None, orientation='bottom', *args, **kargs):
ImageView.__init__(self, parent, orientation, *args, **kargs)
self.setMouseTracking(True)

def mouseMoveEvent(self, event):
print('hi')

Is there a better way to get mouse move events as opposed to polling the mouse position?

Thanks for your help.


Message has been deleted

L. Smash

unread,
Sep 7, 2015, 10:10:53 AM9/7/15
to pyqtgraph
Hi Aaron,

this might help:

import pyqtgraph as pg

import numpy as np

pg.mkQApp()

imv = pg.ImageView()

imv.show()


a = np.random.normal(size=(100,100))

imv.setImage(a)

imv.setMouseTracking(True)


def mouseMoved(event):

print "mouse moved"


imv.getImageItem().scene().mouseMoveEvent = mouseMoved


Best,

Lars

Aaron

unread,
Sep 7, 2015, 7:16:01 PM9/7/15
to pyqtgraph
Lars,

Thank you very much for the suggestion, that works perfectly!  I was missing that the scene was the one triggering the events.

Have a great one,
Aaron
Reply all
Reply to author
Forward
0 new messages