[GIS] How to insert QGIS project properties “Project Title” as field or token using an expression

print-composerqgstitle

Using QGIS, the "General" project properties dialogue includes a "Project Title" area.

Is it possible to use the information inserted in this dialogue in an expression (specifically including within a label when using Composer)?

Best Answer

In QGIS 2.8, here's how I can get the project title into a text element in a map composer.

Add text element, hit "Insert an expression..."

Go to the Function Editor tab, create a new file, call it "project", and put this in it:

from qgis.core import *
from qgis.gui import *

@qgsfunction(args="auto", group='Custom')
def projtitle(value1, feature, parent):
    proj = QgsProject.instance()
    return proj.title()

Hit the green arrow button to run and that will check the syntax. Save it. Now you should have a new function you can put in the expression editor (in the Custom group), for example:

 [% projtitle( 0 )%]

in the text field for Map Composer text objects replaces it with the title from the settings.

I couldn't get it to work with no arguments, so the 0 is just a dummy.

Here's a screengrab of the various components showing it in action.

project title insertion

Related Question