I have solved it this way:

class MousePosition(QtCore.QObject):
    def __init__(self, status_bar, pl, labels):
        super().__init__()
        self.pl = pl
        self.status_bar = status_bar
        self.labels = labels
        self.proxy = pg.SignalProxy(pl.scene().sigMouseMoved, rateLimit=10, 
slot=self.mousemoved)


    def mousemoved(self, evt):
        pos = evt[0]
        if self.pl.sceneBoundingRect().contains(pos):
            mousePoint = self.pl.vb.mapSceneToView(pos)
            self.status_bar.set_x(mousePoint.x(),self.labels[0])
            self.status_bar.set_y(mousePoint.y(),self.labels[1])
            
class StatusBarKK3:
    def __init__(self, window, plots):
        self.window = window
        self.plots = plots
        self.status_bar = window.statusBar()
        
        self.x_label = QtWidgets.QLabel("x: ")
        self.y_label = QtWidgets.QLabel("y: ")
        
        self.status_bar.addPermanentWidget(self.x_label)
        self.status_bar.addPermanentWidget(self.y_label)
        self.mouse_position = {}
        for (name,pl),labels in plots.items():
            self.mouse_position[pl] = MousePosition(self, pl, labels)
            
    def set_x(self, x, prefix='x'):
        self.x_label.setText(f"{prefix}: {x:8.5g}  ")
    
    def set_y(self, y, prefix='y'):
        self.y_label.setText(f"{prefix}: {y:8.5g}  ")


Where *plots* is a dict with keys being (*name, plotItem*) and value a 
string that I want to show  for the x and y coordinates on the status bar. 
At the moment *name *is not used and I may delete it.

Cheers,
 

Il giorno sabato 9 maggio 2020 00:59:35 UTC+2, Bertram Gilfoyle ha scritto:
>
> Is there a way to find out which viewbox or widget the current mouse 
> coordinates are on?
>
> I'm plotting multiple viewboxes, each with one widget inside, then using 
> SignalProxy to capture sigMouseMoved signals.
> With one viewbox, it's simple but I'm pulling hairs on how to do it with 
> multiple. Goal is to display a simple tooltip (TextItem).
>

-- 
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/35ec1404-b638-4b4d-b298-6f85d5db1c01%40googlegroups.com.

Reply via email to