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):
...
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.
来源:https://stackoverflow.com/questions/19428251/pyqtgraph-when-i-click-on-a-plotitem-how-do-i-know-which-item-has-been-clicked