I want to remove an existing option ("Save As") from context menu of QGIS layer, what I have found so far is, to add new action in the LegendItems, or overwrite completely with new options. But could not find any option using that I would be able to remove an existing default Context menu option.

What I have also seen that there is menuProvider() method available, but could not get any details with this method.

How can I remove existing "Save As" option from the context menu of QGIS?


You need override the current context Menu, using your custom class

Minimal sample code for remove "Export" Option

from qgis.gui import QgsLayerTreeViewMenuProvider

ltv = iface.layerTreeView()
cm = mp.createContextMenu()

for action in cm.actions():
    # Need text value ,this object not have ObjectName
    if action.text() == "Exportar":
    #print (action.objectName())

class CustomMenuProvider(QgsLayerTreeViewMenuProvider):

  def __init__(self, view, actions):
    self.view = view
    self.defaultActions = actions

  def createContextMenu(self):
    if not self.view.currentLayer():
      return None
    m = QMenu()
    return m

provider = CustomMenuProvider(ltv, cm.actions())

Navigate "Settings => Interface Customization" and disable "mActionSaveProjectAs" in the "Menus/mProjectMenu".

  • 1
    That is option to disable QGIS's project, but not the layer, is that ? Jan 22 '19 at 11:45

Not the answer you're looking for? Browse other questions tagged or ask your own question.