I want to set different actions(context menu) for vectors,rasters,etc . class MyMenuProvider(QgsLayerTreeViewMenuProvider): def __init__(self, view): QgsLayerTreeViewMenuProvider.__init__(self) self.view = view def createContextMenu(self): if not self.view.currentLayer(): return None m = QMenu() m.addAction("Show Attribute Table", self.openAttributeTable) return m def openAttributeTable(self): #iface1.openFeatureForm(iface1.activeLayer(), feature, False) iface1.showAttributeTable(iface1.activeLayer()) then using it as view = iface1.layerTreeView() provider = MyMenuProvider(view) view.setMenuProvider(provider) But this sets menu provider for all layers , I want to have different actions for different layers