How to get the current position of the mouse on PlotWidget?

554 views
Skip to first unread message

song whale

unread,
May 11, 2022, 9:34:44 PM5/11/22
to pyqtgraph
Hello. I'm trying to get the coordinates of the mouse when clicked. 
I get some values, but they don't correspond to the bar items on the widget. 
I'd like to know what I did wrong and what should be fixed.
Please take a look at the code that I attached.

c.PNG


getCoordinates.py

Patrick

unread,
May 11, 2022, 10:08:00 PM5/11/22
to pyqtgraph
Hi,

I think you may just need to convert the pixel ("scene") coordinates to the plot ("view") coordinates. There's a function to do this in ViewBox:


Typically, it might be used something like:

mousePoint = self.plot.getViewBox().mapSceneToView(pos)

where pos is a tuple of the scene coordinates, eg. the (110, 620) you are receiving from the event.

Patrick
Reply all
Reply to author
Forward
0 new messages