QGIS Labels – Assign Different Colors to Parts of Text in Labels

colorfontlabelingqgis

I'm using QGIS 2.14.3.

It is now possible to assign different colors (or fonts) to different parts of text in one label (I have seen How to make a different font and color of text in labels? )? If so, how?

Example


Although not perfect, @Knightshound 's comment provided a workaround solution I am happy with so far:
Using multiple rule-based labelling without expression rules and assigning Offset from point placements in order to achieve required result.

Result

Best Answer

Expanding on my comment, start off by getting the different sections of the label you wish to be in different colours/fonts into separate columns in the attribute table. In the layer properties "Labels" tab choose "Rule-based labeling' from the drop-down. Now for the slightly tricky part.

Create a new rule for every word you want to be different. In the "Edit Rule" window "Placement" tab, select 'Around Point'. This bit is now trial and error to find the perfect layout, but using the data defined override for the quadrant (number between 0-8 depending on location, hover over button to see) and specifying a distance away from the point you can quite nicely line up several pieces of text into what appears to be a single string. If you find your labels are disappearing because of overlap, under the "Rendering tab" check 'Show all labels for this layer (including colliding labels)'.

And just to make things a little tidier/easier to manage, when creating your rules try nesting them (drag and drop a rule onto another rule). This way any words that you use repeatedly can still be given a style without having to write a more complex rule. In the print screen below I created a rule based on the ID. I then nested the rule I used for the word 'the' without having to change the rule (as you can see with 'the dog' rule where I had to specify that "t1" = 'the' AND "t2" = 'dog' so that the right 'the' was being chosen). Just remember not to add a label to this parent rule as you will then get duplicate labels popping up.

enter image description here

Related Question