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)
Post by Duan YiHow 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
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/fcc0849e-de76-43f9-8b9d-c06b7ecdfe69%40googlegroups.com
<https://groups.google.com/d/msgid/pyqtgraph/fcc0849e-de76-43f9-8b9d-c06b7ecdfe69%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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/CALiCEadtmpQWruXRxhFvWKR85gTWzV_A3w_XX5YnJH346X76cA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.