Is there a way to add a current user label to the print composer in QGIS.

I thought there might be something similar to the $CURRENT_DATE format available.

This would be in a windows environment.

  • 1
    "$CURRENT_DATE(yyyy-MM-dd)" turned out to be very useful and I included it in many of my composer templates. Are there more of these commands available? Like to automatically show my project's name, or a certain layer name, etc.?
    – SAnderka
    Aug 15, 2012 at 12:02

1 Answer 1


Currently, this is an unfulfilled feature request (see Feature #1385).

You could add your ideas for new 'tokens' (or 'fields' as they are monikered in the request). Remember to include recommended formatting options as per Qt classes for the data type, like has been done with the syntax of $CURRENT_DATE(yyyy-MM-dd), which is resolved using QDate::currentDate().toString( formatText ) and QDate class string formatting.

However, there are better solutions than trying to implement all the types of tokens users might need or request (which could be an every-expanding list).

There are currently at least two means to implement a more robust solution:

A) Label text is optionally generated using the QGIS Expression Editor

This is currently the method used in the advanced labeling engine...

enter image description here

Since Composer labels are not relative to a map layer's data source, the section of Fields and Values would need to be replaced and populated with more appropriate Print Composer tokens, e.g. project name, title, projection, user, etc. (date functions are already in the master branch builds). Luckily, there has been work by developers to make it relatively 'easy' to add new expression sections, though it would still take some work. Additional work would also be needed to accommodate new tokens.

B) Label text (or tokens) is optionally the result of Python snippet(s)

While not as user-friendly as the Expression Editor solution, since it requires an understanding of Python, the implementation of such a feature would possibly only require a single development effort. Then, any textual aspect of a QGIS project, including its various Composer items, available via the PyQGIS API (i.e. Python Console), could be accessed, formatted and output to text.

The Python snippets could be wrapped in individual tokens and embedded in the current text of the text edit box, or be contained in an separate text edit box in the GUI, activated by check box. For security reasons, the code would probably not be auto-run on Composer launch (could be an option to allow always, though).

The separate text edit box approach would allow for Python code validation and the keying of specifically named Python functions, for example the following snippet:

import getpass
from qgis.core import *

def pytoken_user():
    return getpass.getuser()

def pytoken_title():
    return QgsProject.instance().title()

would replace any number of in-text tokens named $pytoken_user or $pytoken_title.

Both of the above solutions are considerably more extensible than implementing individual tokens in-line in the QGIS source code. There may be other or better solutions, as well.

Dr. Hugentobler has recently been re-working the Print Composer in QGIS's master branch, so now is an ideal time to request such labeling features for the next version of QGIS. I'll add a feature request for these two ASAP.

  • See associated feature request at hub.qgis.org.
    – dakcarto
    Aug 31, 2012 at 21:42
  • Did either of these solutions make it into a release version of QGIS? Or is this still in development? Thanks
    – user15881
    Mar 7, 2013 at 9:03

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.