I'm printing QR-code that is generated on the fly in QGIS Print Composer. The URL to get the QR-code ist stored in a PostgreSQL database in the attribute-field "url".

<img src = "[% "url" %]"  
    style="width: auto; height: 100%; display: block; margin: 0px 0px 0px auto;" />

In Print Composer this works fine as long as the map, I use is part of an Atlas. When the map switches to another Atlas-feature, the generated QR-code is updated.

My problem is, that I want to use a map without the Atlas functionality. How can I get the URL only for the feature (supposing that only one feature is displayed) that is displayed on the map in Print Composer?

I was looking trough the expressions from QGIS, but did not find a suitable function to catch the data of a feature on a defined layer within the extent of a a map in Print Composer.

  • you can try something like: attributes(get_feature('layername_or_layerid','field_to_identify','value_to_identify'))['atttributename'] – eurojam Jan 10 at 8:39

Etape 1

Define an item id in the item properties of your map (example : map1)

In the scope of the layout you have now access to the properties of the item map1 with the function the expression


You could have the extent of the map1 with :


Etape 2

Add your label with the expression :

    map_get(item_variables('map1'), 'map_extent'),
            filter:=intersects($geometry, @map_extent)

It uses the with_variable function to create the map_extent variable (@map_extent) to make the expression more readable.


You may have some bug with the message "No feature was found on this layer to evaluate the expression.". If you can note validate the expression, just copy/paste your expression with the [% ... %] outside the expression builder.

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.