Geographic Information Systems Asked by Marcelo Freitas on December 29, 2020
I have the following map but I don’t know how to make a title appear on top of it. Any suggestion on how to?
Depending of your requirements, you may want to use a QgsLayoutItemLabel
or a QgsLayoutItemHtml
. To illustrate, we use QgsLayoutItemLabel
. For QgsLayoutItemHtml
, you may look at this existing question and its answers
from qgis.core import QgsLayoutItemLabel, QgsLayoutPoint, QgsLayoutSize
from qgis.PyQt.QtCore import Qt
project = QgsProject.instance()
manager = project.layoutManager()
layout = manager.layoutByName('demo')
new_layout_item_label = QgsLayoutItemLabel(layout)
layout.addLayoutItem(new_layout_item_label)
new_layout_item_label.setText("My title")
new_layout_item_label.setHAlign(Qt.AlignCenter)
new_layout_item_label.setVAlign(Qt.AlignVCenter)
new_layout_item_label.attemptResize(QgsLayoutSize(page_size.width(), 20, QgsUnitTypes.LayoutMillimeters))
new_layout_item_label.attemptMove(QgsLayoutPoint(0, 0, page_size.units()))
Answered by ThomasG77 on December 29, 2020
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP