I read the QGIS 3.2 Changelog and saw a new feature to add text on top of symbols for vector layers. Does anyone knows how to do this?

enter image description here

  • 1
    Just to avoid any misunderstanding, this feature is a LEGEND feature, meaning that the text is added on top of the legend, not on the map symbology
    – J.R
    Jun 25 '19 at 12:28
  • In ahmadhanb's example, how can I display the text in the symbols with the same colors as in the rule-based labeling of the layer on the map? With the example of csk this works in principle. Only if I create the label based on a field, e.g. "code", the legend in the layout will not show one of the letters from "code" but the text [code] on the legend symbol. Testet with QGIS 3.10.5 (works with QGIS 3.12.2)
    – GJ_gis
    Apr 27 '20 at 9:49

Right-click the the target layer -> Properties -> Legend and click on Set Labels from expression:

enter image description here

In expression you can write whatever you want, for example:

 substr( "FieldName",4,1)

Click Apply and OK

enter image description here


enter image description here


As J.R. pointed out, the feature mentioned in the 3.2 changelog is a LEGEND feature, meaning that the text is added on top of the legend, not on the map symbology. ahmadhanb perfectly explained how to implement this feature. If you want to display text on top of the map symbols, see below.

Here's how to add text on top of the symbols on the map:

Method One: non-repeating text (once per feature)

Open the Labels tab of the Layer Styling Panel. Choose "single labels" from the first drop-down menu. If your label text is stored in an attribute table field, select that field from the Label with dropdown menu. If you want to label each feature with the same text, simply type that text into the Label with text box, surrounded by single quotation marks. Eg, to display the text thisismylabel on each feature, type 'thisismylabel'.

enter image description here

Method Two: repeating text

In the Symbology tab of the Layer Styling Panel, add a symbol level. If using a categorized symbol, click the Change symbol button, then add a symbol level.

Change the new symbol level to a point marker, and change the marker type to font marker.

enter image description here

In the font marker section, scroll down to the symbol selector area. Click the 'data-defined settings button' next to the symbol selector, and choose the field with the label text.

enter image description here

Now you should see repeating text on every polygon.

enter image description here

To access the settings for how far apart the text markers are spaced, highlight 'point pattern fill' in the symbol layer display.

enter image description here

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.