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

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, privacy policy and cookie policy

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