disable some functions of right-click menu

211 views
Skip to first unread message

Duan Yi

unread,
Dec 4, 2018, 7:55:26 AM12/4/18
to pyqtgraph
How can I disable/customize the functions of the right-click menu in pyqtgraph? Much appreciated.

Dejan Penko

unread,
Dec 4, 2018, 8:56:22 AM12/4/18
to pyqt...@googlegroups.com
Code example. I don't guarantee that copy-paste will work as It is only a part of my whole code, but it should give you some tips and ideas.
import pyqtgraph as pg

class MyCustomPlotContextMenu(pg.ViewBox):
    """Subclass of ViewBox.
    """

    def __init__(self parent=None):
        """Constructor of the QVizCustomPlotContextMenu

        super(MyCustomPlotContextMenu, self).__init__(parent)
# Set original plot context menu # Note: self.menu must not be None (this way works fine for plotWidgets, # but not for GraphicsWindow) self.menu = pg.ViewBoxMenu.ViewBoxMenu(self) # Menu update property self.menuUpdate = True def getMenu(self, event=None): """Modify the menu. Called by the pyqtgraph.ViewBox raiseContextMenu() routine. Note: Overwriting the ViewBox.py getMenu() function. """ if self.menuUpdate is True: # Modify contents of the original ViewBoxMenu for action in self.menu.actions(): # Modify the original Mouse Mode if "Mouse Mode" in action.text(): # Change action labels for mouseAction in self.menu.leftMenu.actions(): if "3 button" in mouseAction.text(): mouseAction.setText("CustomLabel1") elif "1 button" in mouseAction.text(): mouseAction.setText("CustomLabel2") # Add custom contents to menu self.addCustomToMenu() # Set menu update to false self.menuUpdate = False return self.menu def addCustomToMenu(self): """Add custom actions to the menu. """ self.menu.addSeparator() # Autorange feature self.actionAutoRange = QAction("Auto Range", self.menu) self.actionAutoRange.triggered.connect(self.autoRange) # - Add to main menu self.menu.addAction(self.actionAutoRange) # - Add to main menu self.menu.addAction(self.actionConfigurePlot)
To set your custom contextMenu as default one, you have to set it as a 'viewBox' argument

Example: 

myPlotWidget = pg.PlotWidget(parent, viewBox=MyCustomPlotContextMenu)


On Tue, 4 Dec 2018 at 13:55, Duan Yi <yi.du...@gmail.com> wrote:
How can I disable/customize the functions of the right-click menu in pyqtgraph? Much appreciated.

--
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 pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/fcc0849e-de76-43f9-8b9d-c06b7ecdfe69%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages