enter image description here

How can i make it so the legend on the left bottom don't cover the map?

  • When you say, "How can i make it so the labels don't cover the map?" You speak about the legend labels on the left bottom or the red text value on each region? Need to be sure to answer correctly – ThomasG77 May 30 '20 at 22:53
  • Hey @ThomasG77, I was thinking about the legend labels on the left bottom – Marcelo Freitas May 31 '20 at 0:12
  • Why don't you move it? I see you already manipulate the position. Or you can make the map size width with total width minus legend width to avoid any overlay between map and legend? Suggestions but I do not know your intent – ThomasG77 May 31 '20 at 0:20

Although in the layout, I suggested changing legend block position or reduce the map canvas to avoid overlay, a recipe to make some changes to your fonts in the legend

project = QgsProject.instance()
manager = project.layoutManager()
layout = manager.layoutByName('demo')

# I start from an existing QgsLayoutItemLegend named "legend1"
# here. You may create your own and insert it in the layout
legend1 = layout.itemById('legend1')
# Options you can try, not mandatory to answer your question
# legend1.setColumnCount(3)
# legend1.setEqualColumnWidth(True)
# legend1.setSplitLayer(True)

# Default style when automatic legend, you may look at https://qgis.org/api/classQgsLegendStyle.html#acae0c6c735f4cb36f30fc53df74bd84e to change styles for other legend blocks (match "Fonts and Text Formatting" section)

  • legend.setScale(2) i changed the legend scale and that fixed my problem – Marcelo Freitas May 31 '20 at 13:10
  • Happy for you it works. Surprised you can use setScale as it's undocumented for the class QgsLayoutItemLegend (including inherited methods) qgis.org/api/… PS: I've tested too your solution and it seems a missing part in the API doc – ThomasG77 May 31 '20 at 14:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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