3

QGIS Zurich 3.18.2 -Win10

I have a virtual layer that has multiple polygons each with two pertinent Attribute fields. "Field1Name" and "Field2Name". I can set and Style the Label for one field and I can display these two fields as a Label, using the Expression Value "field1name" || '\n' || "field2name".

BUT is it possible to set a different Text/Render Style for each of the two fieldnames in the Label to display at the same time? I want both fields data to appear within the polygon label, but one highlighted, bold and large and the other subordinated, smaller less obvious. If I set up two Text Styles up is there an Expression that will achieve this two component styled Label?

MrXsquared
  • 34,292
  • 21
  • 67
  • 117
TonySomerset
  • 101
  • 8
  • Do you mean something like https://gis.stackexchange.com/q/83686/99589, if yes we can close your thread as a duplicate. – Taras May 11 '21 at 10:54
  • 1
    half yes half no Yes as my text, I can stack two Labels vertically but no as I want to Style them individually it seems the Rule Based labelling may give me the solution. Working on it – TonySomerset May 12 '21 at 13:05

1 Answers1

3

Yes this is possible. To do this you need to set labelling to rule based labelling. One rule will be for your top line and the second rule for the bottom line. You don't to set any filters for the rules but you can set them to display different fields and have different label symbologies. There may just be a little bit more effort involved in getting the spacing correct between the different lines as you will probably have to do this using offsets instead of a line break.

EDIT: To edit the vertical spacing for each rule: open the rule's properties, go to Placement, set the mode to 'Offset from Point', and adjust the offsets under Offset,X,Y. Y adjustment highlighted here: enter image description here

TeddyTedTed
  • 6,100
  • 1
  • 11
  • 36
  • been struggling and can find no way to change the y on either Rule. So how do you Offset? – TonySomerset May 12 '21 at 14:39
  • @TonySomerset See the edit to my answer. – TeddyTedTed May 12 '21 at 15:13
  • 1
    oh excellent, just what I wanted. Spent all afternoon, So simple when you know what to look for! It is Offset from Centroid. Think I got it right, you have to create a Single Label in turn assign it a Text Style then create your Rule Based labels and they will come in with the assigned Text Style – TonySomerset May 12 '21 at 16:00