def mouseClickEvent(self, mouseClickEvent): """ Handles (PyQtGraph) mouse click events. Overrides the middle mouse click to reset using the settings in the config tree. Opens the context menu if a right mouse button was clicked. (We can't simply use setContextMenuPolicy(Qt.ActionsContextMenu because the PlotItem class does not derive from QWidget). :param mouseClickEvent: pyqtgraph.GraphicsScene.mouseEvents.MouseClickEvent """ if mouseClickEvent.button() in self.resetRangeMouseButtons: self.emitResetColorScaleSignal() mouseClickEvent.accept() elif mouseClickEvent.button() == QtCore.Qt.RightButton: contextMenu = QtWidgets.QMenu() for action in self.actions(): contextMenu.addAction(action) screenPos = mouseClickEvent.screenPos( ) # Screenpos is a QPointF, convert to QPoint. screenX = round(screenPos.x()) screenY = round(screenPos.y()) contextMenu.exec_(QtCore.QPoint(screenX, screenY)) else: super(ArgosColorLegendItem, self).mouseClickEvent(mouseClickEvent)
def mouseClickEvent(self, mouseClickEvent): """ Handles (PyQtGraph) mouse click events. Opens the context menu if a right mouse button was clicked. (We can't simply use setContextMenuPolicy(Qt.ActionsContextMenu because the PlotItem class does not derive from QWidget). :param mouseClickEvent: pyqtgraph.GraphicsScene.mouseEvents.MouseClickEvent """ if mouseClickEvent.button() == QtCore.Qt.RightButton: contextMenu = QtWidgets.QMenu() for action in self.actions(): contextMenu.addAction(action) screenPos = mouseClickEvent.screenPos() # Screenpos is a QPointF, convert to QPoint. screenX = round(screenPos.x()) screenY = round(screenPos.y()) contextMenu.exec_(QtCore.QPoint(screenX, screenY))