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
  •  | 
  •  

문제

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top