I have created a blank print layout, now I want to add items to it like a map, legend, etc.
Here is my code so far to create a new print layout, this works just fine:
#This creates a new print layout project = QgsProject.instance() manager = project.layoutManager() layout = QgsPrintLayout(project) layout.initializeDefaults() layout.setName('My Layout') manager.addLayout(layout)
Now I want to add stuff to the layout, starting with a map:
map_item = QgsLayoutItemMap.create(layout)
What does this mean "the caller takes responsibility for deleting the returned object" and how do I add a map (or other) objects to my Print Layout?