3

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?

Ville Koivisto
  • 688
  • 1
  • 7
  • 24
Vali
  • 61
  • 7

1 Answers1

7

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()
doc.setContent(template_content)

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

look at the API loadFromTemplate()

Fran Raga
  • 7,838
  • 3
  • 26
  • 47