Hi,

There's probably a few ways to do this, but the simplest modification to 
your code would be to use a lambda expression to wrap the mouseMoved 
function and pass in the appropriate widget. It might look something like 
this:

def mouseMoved(widget, pos): 
     widget.getViewBox().mapSceneToView(pos)   
     xCor = mousePoint.x() 
     yCor = mousePoint.y()   
     print( xCor, yCor)   

for w in [pwidget1, pwidget2, pwidget3]:
    w.scene().sigMouseMoved.connect(lambda pos: mouseMoved(w, pos))

I'll also add that if you ever need to do some complicated event handling 
that is not possible in pyqtgraph, then remember that everything in 
pyqtgraph is a Qt object, which means you can go directly to the Qt event 
layer to catch and manipulate events at a low level. The EventFilter is 
very powerful in this regard: 
https://doc.qt.io/qtforpython/overviews/eventsandfilters.html

Patrick

On Saturday, 14 May 2022 at 12:59:40 pm UTC+9:30 song whale wrote:

> Hello. If there are multiple docks and their corresponding widgets inside 
> one DockArea, how can I get the mouse pointer coordinates?
>
>
> def mouseMoved(pos): 
>      qwidget.pwidget  .getViewBox().mapSceneToView(pos)   
>      xCor = mousePoint.x() 
>      yCor = mousePoint.y()   
>      print( xCor, yCor)   
>
> qwidget.pwidget.scene().sigMouseMoved.connect(mouseMoved)
>
>
> If I use the fuction above, I need to specify which widget the mouse is on 
> in advance. 
> Are there any convenient ways to determine the mouse position in a 
> situation where there are multiple widgets, or is there a method that tells 
> you which widget the mouse is on?
>

-- 
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/0f0818d0-3e3b-4f13-ae9a-04d99f6a5f23n%40googlegroups.com.

Reply via email to