detect mouse button release event

662 views
Skip to first unread message

Daniel Bushey

unread,
Apr 26, 2017, 11:25:05 AM4/26/17
to pyqtgraph
Hi, I am new to pyqtgraph. I am trying to generate rois in an image using tool that behaves similar to lasso (photoshop) or imfreehand (matlab). So, I would like to place the mouse cursor on a particular point in the image, button press, start moving the mouse around a region of interest while recording x,y coordinates, and then release the mouse closing the selection process. These coordinates can then be passed to generate an roi. I've been modifying the class ImageView adding:
self.view.scene().sigMouseMoved2.connect(self.mouseMoved)
self.view.scene().sigMouseClicked.connect(self.mouseClicked)
These two additions allow me to see mouse movements in the def mouseMoved and initiate roi drawing in def mouseClicked. However, I cannot find a means to detect when the user releases the mouse button. Ideally, there would be a signal released when the button is released (ie self.view.scene().sigMouseReleased.connect(self.mouseRelease) but no such call exists in the class GraphicsScene. The other means would be detect if the button is no longer being pressed using the qt event passed into the mouseMoved definition. Unfortunately, the event being passed is only the positional data. I've tried modifying the class GraphicsScene def mouseMoveEvent so all the event data is passed (self.sigMouseMoved.emit(ev.scenePos()) to self.sigMouseMoved.emit(ev)). However, the event.button() does not give the correct button (==0) although from sigMouseClicked the event emitted does give the correct button signal (event.button() == 1 , which the left mouse button). 

I suppose I could have a mouse click beginning and a second click ending the roi but this would make the tool work differently than in other programs causing confusion with some users.

Any ideas on how to detect whether the mouse button is being pressed or has been released would be appreciated. Within class GraphicScene, there are def mouseReleaseEvent and def sendDragEvent but I cannot find an example using these definitions and don't understand how these definitions work.
Thank you,
Dan

Daniel Bushey

unread,
May 2, 2017, 9:36:05 AM5/2/17
to pyqtgraph
I found a solution. The self.view.scene().clickEvents records the mouse press button event and changes when the mouse button is released.

Friedrich

unread,
Sep 23, 2018, 10:20:43 AM9/23/18
to pyqtgraph
hi

i hope you will still read this since i am struggling with the signals... could you give me a short example on how you did it?
Reply all
Reply to author
Forward
0 new messages