2

I am trying to find information about how to programmatically import new composer from template, but it is impossible.

There is a lot of information how to print the composer to image, but not save it in the project *.qgs.

Has anyone got any experience of loading new composer to project QGIS and open it from list "Print composers"?

Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Evgeny Z
  • 81
  • 4

1 Answers1

6

This is solve for me.

myFile = os.path.join('r:/Graf/_temp/Templates/', 'template.qpt')
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()
myTemplateFile.close()
myDocument = QDomDocument()
myDocument.setContent(myTemplateContent, False)
newcomp = self.iface.createNewComposer()
newcomp.composition().loadFromTemplate(myDocument)
Kadir Şahbaz
  • 76,800
  • 56
  • 247
  • 389
Evgeny Z
  • 81
  • 4