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"?

0

1 Answer 1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.