0

I set the legend text using the code below but upon saving, closing and reopening the QGIS project the legend text reverts back to the layer name.

project = QgsProject.instance()
manager = project.layoutManager()
layout = manager.printLayouts()[0]
legend = QgsLayoutItemLegend(layout)
.
.
.
legend.setAutoUpdateModel(False)
root = legend.model().rootGroup()
root.removeAllChildren()
leg_layer = root.addLayer(layer)
leg_layer.setUseLayerName(False)
leg_layer.setName('layer legend text')
legend.model().setRootGroup(root)
layout.addLayoutItem(legend)
2
  • and what is your question?
    – eurojam
    Feb 14 at 16:25
  • Does the same problem occur if you do it manually in the application instead of using PyQGIS? Feb 15 at 0:11

0

Browse other questions tagged or ask your own question.