5

Is there a way to to have a map (Print Composer) open automatically upon project load?

I have a map constructed in Print Composer "General Map".

When a user fires off the project, I would like "General Map" to open by default.

2 Answers 2

4

I'm not aware of any way to designate the print composer to open as a default action of the QGIS software. Also, I'm not sure if there is a plug-in either, I would imagine if there was this capability available it would be available as a plug-in unless the QGIS developers move to having the print composer open as a default option.

Furthermore, I came across a discussion in a different forum that discusses the thought process amongst some QGIS developers about the reason to not having this as a default option but rather encouraging users to utilize the template load option for customization of each print composer for a particular project.

2

As @whyzar already mentioned, I don't think there's a setting or plugin which could achieve this directly (not yet anyway).

However, you can achieve this by using a Python script inside a macro (script adapted from this post, credit to @Matt) which runs whenever the project is loaded. Note that the Print composer template must be saved separately as the following script loads this .qpt file:

import os, qgis
from PyQt4.QtXml import QDomDocument

# Change path and name of template accordingly
myFile = os.path.join('C:/Users/You/Desktop//', 'General Map.qpt')
myTemplateFile = file(myFile, 'rt')
myTemplateContent = myTemplateFile.read()
myTemplateFile.close()
myDocument = QDomDocument()
myDocument.setContent(myTemplateContent, False)
newcomp = qgis.utils.iface.createNewComposer()
newcomp.composition().loadFromTemplate(myDocument)

From the toolbar, insert the script in:

Project > Project Properties... > Macros

Script to load composer template

Make sure you do the following:

  • Save your project

  • Enable macros by going to:

    Settings > Options > General > Project files

    Enable macros

Now when the project is loaded, the composer template should pop up.

2
  • 1
    That is a neat script to make this feature available
    – whyzar
    Feb 29, 2016 at 12:44
  • 1
    @whyzar - Thank you buddy but the script has been mentioned in several posts such as this one so I just borrowed it ;)
    – Joseph
    Feb 29, 2016 at 12:49

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.