Friday, 10 May 2019

pyqgis - Removing the existing context menus from legendlayeractions QGIS 2.6.1 using python


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



Answer




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.


No comments:

Post a Comment