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?

enter image description here


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)
new_layout_item_label.setText("My title")

new_layout_item_label.attemptResize(QgsLayoutSize(page_size.width(), 20, QgsUnitTypes.LayoutMillimeters))
new_layout_item_label.attemptMove(QgsLayoutPoint(0, 0, page_size.units()))

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.