I am developing a script to print different map views of a QGIS project. I want to print all the vector layers in the canvas but I don´t want one of them to appear in the legend. I can`t figure out the way to do it.

  • 2
    what have you tried and which part does not work? please show us code you developed and which does not work
    – LaughU
    Nov 9, 2017 at 9:04

1 Answer 1


Try this:

    legend = QgsComposerLegend(c)
    lyrGroup = QgsLayerTreeGroup()
    for legendLyr in iface.mapCanvas().layers():
        if legendLyr.name() != "layer_you_dont_want"
    c.addComposerLegend(legend) # c is your composer

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