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)
But I get the following error:
When I look at the documentation for QgsLayoutItemMap.create I see this, except I do not understand it:
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?