8

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?

5
2

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()
mp=ltv.menuProvider()
cm = mp.createContextMenu()

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

class CustomMenuProvider(QgsLayerTreeViewMenuProvider):

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

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


provider = CustomMenuProvider(ltv, cm.actions())
ltv.setMenuProvider(provider)
-2

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

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

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