a = QAction( u"My Action", iface1.legendInterface() )
iface1.legendInterface().addLegendLayerAction( a, u"My Plugin Menu", u"id1", QgsMapLayer.VectorLayer, True )   #adds action
iface1.legendInterface().removeLegendLayerAction(a) #removes action

removes user made actions . I want to take out all the inbuilt context menu actions


Since QGIS 2.4 you can use QgsLayerTreeView for that.

Remove all Layers Panel (legend) context menu actions:

ltv = iface.layerTreeView()
ltv.setMenuProvider( None )

Remove all and add only your own action: see Display of context menu section by Martin Dobias.

  • can we have different actions for different layers?
    – drama
    Jul 25 '17 at 10:21
  • You set a menu provider for the whole layer tree, but have a look at Martin's post (second link in my answer), there you see you could easily set specific actions for vectors, other actions for rasters, etc. Everything depends on your use case, as always. Jul 25 '17 at 14:15
  • can u please give an example for setting different actions for vectors ,rasters,etc
    – drama
    Jul 27 '17 at 6:52
  • Please ask a new question in GIS.SE for that, then I could post an answer. Jul 27 '17 at 12:12
  • ya sure ,@ Germán Carrillo
    – drama
    Jul 27 '17 at 12:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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