I'm trying to load a print layout (.qpt) which I saved earlier via PyQgis.

I found this earlier entry, but it's for QGIS 2.x and thus doesn't work for QGIS3: Programmatically load composer from template and generate atlas using pyQgis

Does anyone know how to do this in QGIS3?


For load qpt in QGIS 3 you need something like this:

# Load template from file
p = QgsProject()
l = QgsLayout(p)
tmpfile = 'D://temp//test.qpt'
with open(tmpfile) as f:
    template_content = f.read()
doc = QDomDocument()

# adding to existing items
items, ok = l.loadFromTemplate(doc, QgsReadWriteContext(), False)

look at the API loadFromTemplate()

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.