TransWikia.com

How to resize label in PyQGIS?

Geographic Information Systems Asked on February 1, 2021

enter image description here

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

One Answer

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)
legend1.styleFont(QgsLegendStyle.Subgroup).setPointSize(14)
legend1.setFontColor(QColor('#ff0000'))

legend1.refresh()

Answered by ThomasG77 on February 1, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP