This question has been asked in the past but those questions were either not answered or suggested solutions that required multiple labels separated by newlines and placement rules to simulate a contiguous label.
Does the label engine in QGIS currently allow styling substrings based on rules? I'm writing a quick tutorial for a GIS class on labelling, and I'm seeing if a label like this:
"name_en" || '\n' || 'is a ' || lower("category") || ' site which is ' || case when "danger" = 1 then 'under threat.' else 'not under threat.' end
Can be modified so that the contents of the field
"name_en" is displayed in bold, whereas the rest of the string is displayed using regular font. For reference, the data in question is UNESCO's list of World Heritage Sites, available here.
I can get there by splitting them up in two and devising a rule for
"name_en" separately, but that feels like a wonky solution. I've tried several expressions in the
'data defined override' button, but the result always comes back as either all bold or all regular. It expects a boolean argument, so that kind of assumes the output (i.e. any given label) will always be either all bold or all regular.
I assume the answer will involve something like using the length of the name_en string to apply the bold style to the first n characters, or:
But I'm not finding a way to use that kind of logic to style a substring of a label.