pyqtgraph: When I click on a PlotItem how do I know which item has been clicked

StackOverflow https://stackoverflow.com/questions/19428251

  •  01-07-2022
  •  | 
  •  

Pregunta

I don't konw if my method is the right method, but it works.

class PltItem(pg.PlotItem):

    pltClicked = Signal()

    def __init__(self, parent = None):
        super(PltItem, self).__init__(parent)

    def mousePressEvent(self, ev):
        super(PltItem, self).mousePressEvent(ev)
        self.pltClicked.emit()

the in the main window i use

for i, plt in enumerate(self.plts):
    self.connect(plt, SIGNAL("pltClicked()"), partial(self.selectplot, i))

def selectplot(self, i):
    ...
¿Fue útil?

Solución

Your solution is a good one. Another solution is to connect to the GraphicsScene.sigMouseClicked signal and use QGraphicsScene.items() to determine whether a PlotItem (or any other item) was under the click.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top