3

I would like to load new composers from template files (*.pqt) when I open my plugin.

I managed to do it using this helpful post Programmatically import new composer from template to project using pyQgis

But as explain in QGIS API doc, when using createNewComposer, the composer window will be shown and activated.

Is there a way to automatically close the composer window, then loading template would be 'transparent' for plugin user ?

2

Maybe a little bit late but I had the same problem and I figured this out (assuming you want to close the first composer):

activeComposer = iface.activeComposers()
composer = activeComposer[0]
composerWindow = composer.composerWindow()
composerWindow.close()
0

Alternatively, to match the code from your linked answer:

newcomp = self.iface.createNewComposer()
newcomp.composition().loadFromTemplate(myDocument)
newcomp.composerWindow().close()

And as proof that the composer itself hasn't been deleted.

newcomp.composerWindow().show()

Makes the window reappear. Test in 2.18.2

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.