This expression [%@project_path%] prints the path of the qgis project.

How the Map Theme used in the layout can also be printed automatically ?

According to QGIS documentation, a Map Theme is a snapshot of the current map legend that records.

How to reproduce the issue

The Map Theme is set according to these steps :

  1. View tab > Panels > Layers

enter image description here

  1. Click on the Manage Map Themes icon > Add Theme

enter image description here

  1. Give the new Map Theme a name

enter image description here

  1. Open a new Print Layout > click on Adds a new Label to the Layout > create one

enter image description here


Does a variable or an expression exist to automatically print the name of the Map Theme in the Print Composer?

Answer 1 (not entirely satisfactory)

  1. create manually a Map Theme
  2. open Python console > iface.mapCanvas().setTheme('your theme')
  3. open Print Composer > add a new map to the layout > Item propriety tab > Item ID > write what you want
  4. add a new Label to the Layout > item propriety > click insert an expression button > function editor tab > click '+' button > insert the code below :

    from qgis.core import * from qgis.gui import * from qgis.utils import iface

    @qgsfunction(args='auto', group='Custom') def print_theme(value1, feature, parent): return iface.mapCanvas().theme()

  5. Expression tab > print_theme('_your_map_id_')

  • Can you specify what you mean by map theme and/or give an example? Also how would your data be structured?
    – MrXsquared
    Commented Jan 11, 2019 at 12:49
  • 1
    @MrXsquared, the data is structured in the Map Theme. The Objective is to see Theme1 in the Print Layout.
    – geavcon
    Commented Jan 11, 2019 at 13:36
  • 2
    It can be done using a custom function that returns iface.mapCanvas().theme() but it seems to only work if the theme is set programmatically (e.g. through the Python console) with iface.mapCanvas().setTheme('My theme'). See gis.stackexchange.com/questions/293507/…
    – Matt
    Commented Jan 11, 2019 at 13:54
  • Thanks @MattNeedle! The Map Theme used can be seen in the Print Composer. However, as you mention it, the solution is not fully automatic and contains certain problems (map themes can't be changed manually once they are changed with pyqgis)... Lastly, it seems that this solution works only with QGIS 3.
    – geavcon
    Commented Jan 15, 2019 at 15:42
  • 1
    Maybe that's a good feature request for a future QGIS version? Having access to the map object's theme as a variable could be very useful.
    – Gabriel
    Commented Jan 15, 2019 at 16:07

1 Answer 1


An atlas could do the job and even set the theme (or preset) for each image in case you have more than one:

  1. Create a layer to guide the atlas and themes:
  2. Control the composer by atlas.
  3. In the map options, set the the layers followed by function and then:
  4. Select the atlas attribute that defines the theme. (This name must be exactly the same as the defined in the theme layers).
  5. Show the theme attribute in the text box.

Here the screenshots of the process. I hope it helps.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

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.