18.2.4. A rotulagem de item

o item: guilabel: Label ‘é uma ferramenta que ajuda a decorar seu mapa com textos que ajudam a entendê-lo; pode ser o título, autor, fontes de dados ou qualquer outra informação…Você pode adicionar um rótulo com o | label | : guilabel: `Adicionar etiqueta ferramenta a seguir: ref:` itens instruções de criação <create_layout_item>`e manipule-a da mesma maneira como exposto em: ref:` interact_layout_item

By default, the label item provides a default text that you can customize using its Item Properties panel. Other than the items common properties, this feature has the following functionalities (see Fig. 18.23):


Fig. 18.23 Painel de propriedades do item de etiqueta Propriedades principais

O grupo: guilabel: Propriedades principais é o local para fornecer o texto (ele pode estar em HTML) ou a expressão para criar o rótulo. As expressões precisam estar entre `` [% `` e ``%] `` para serem interpretadas como tal.

  • As etiquetas podem ser interpretados como código HTML: check | caixa de seleção | : guilabel: Renderizar como HTML. Agora você pode inserir um URL, uma imagem clicável vinculada a uma página da Web ou algo mais complexo.

  • You can also use expressions: click on Insert or Edit an expression… button, write your formula as usual and when the dialog is applied, QGIS automatically adds the surrounding characters.


Clicking the Insert or Edit an Expression… button when no selection is made in the textbox will append the new expression to the existing text. If you want to update an existing text, you need to select it the part of interest beforehand.

You can combine HTML rendering with expressions, leading to advanced labeling. The following code will output Fig. 18.24:

      /* Define some custom styles, with attribute-based size */
      name {color:red; font-size: [% ID %]px; font-family: Verdana; text-shadow: grey 1px 0 10px;}
      use {color:blue;}

   <!-- Information to display -->
   <u>Feature Information</u>
   <ul style="list-style-type:disc">
     <li>Feature Id: [% ID %]</li>
     <li>Airport: <name>[% NAME %]</name></li>
     <li>Main use: <use>[% USE %]</use></li>
   Last check: [% concat( format_date( "control_date", 'yyyy-MM-dd'), ' by <b><i>', @user_full_name, '</i></b>' ) %]

   <!-- Insert an image -->
   <p align=center><img src="path/to/logos/qgis-logo-made-with-color.svg" alt="QGIS icon" style="width:80px;height:50px;"</p>

Fig. 18.24 Leveraging a label with HTML styling Aparência

  • Define Font by clicking on the Font… button or a Font color by pushing the color widget.

  • You can specify different horizontal and vertical margins in mm. This is the margin from the edge of the layout item. The label can be positioned outside the bounds of the label e.g. to align label items with other items. In this case you have to use negative values for the margin.

  • Using the text alignment is another way to position your label. It can be:

    • Left, Center, Right or Justify for Horizontal alignment

    • and Top, Middle, Bottom for Vertical alignment. Explorando expressões em um item de etiqueta

Below some examples of expressions you can use to populate the label item with interesting information - remember that the code, or at least the calculated part, should be surrounded by [% and %] in the Main properties frame:

  • Display a title with the current atlas feature value in “field1”:

    'This is the map for ' || "field1"

    or, written in the Main properties section:

    This is the map for [% "field1" %]
  • Adicione uma paginação para recursos de atlas processados (por exemplo, `` Página 1/10 ‘’)

    concat( 'Page ', @atlas_featurenumber, '/', @atlas_totalfeatures )
  • Return the name of the airports of the current atlas region feature, based on their common attributes:

    aggregate( layer := 'airports',
               aggregate := 'concatenate',
               expression := "NAME",
               filter := fk_regionId = attribute( @atlas_feature, 'ID' ),
               concatenator := ', '

    Or, if an attributes relation is set:

    relation_aggregate( relation := 'airports_in_region_relation',
                        aggregate := 'concatenate',
                        expression := "NAME",
                        concatenator := ', '
  • Return the name of the airports contained in the current atlas region feature, based on their spatial relationship:

    aggregate( layer := 'airports',
               aggregate := 'concatenate',
               expression := "NAME",
               filter := contains( geometry( @parent ), $geometry ),
               concatenator := ', '


    array_to_string( array:= overlay_contains( layer := 'airports',
                                               expression := "NAME" ),
                     delimiter:= ', '
  • Return the lower X coordinate of the Map 1 item’s extent:

    x_min( map_get( item_variables( 'Map 1' ), 'map_extent' ) )
  • Retrieve the name of the layers in the current layout Map 1 item, and formats in one name by line:

      map_get( item_variables( 'Map 1' ), 'map_layers' ), -- retrieve the layers list
      layer_property( @element, 'name' ) -- retrieve each layer name
     '\n' -- converts the list to string separated by breaklines