0

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.

1
  • 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 '17 at 9:04
4

Try this:

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

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