Discussion:
[pyqtgraph] detect mouse button release event
Daniel Bushey
2017-04-26 15:25:05 UTC
Permalink
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
--
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 pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/267a20a4-d020-4dee-9ae9-ee6cff389235%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Daniel Bushey
2017-05-02 13:36:05 UTC
Permalink
I found a solution. The self.view.scene().clickEvents records the mouse
press button event and changes when the mouse button is released.
Post by Daniel Bushey
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
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
--
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 pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/1b7f2155-78ab-472e-8e63-c4725ab11290%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Friedrich
2018-09-23 14:20:42 UTC
Permalink
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?
--
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 pyqtgraph+***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/0f75f7fa-8e5c-4cbe-aa50-773693b00377%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Continue reading on narkive:
Loading...