Is it possible to create a dashed underline for labeling in QGIS? I have one capital city which for used underline for the name of this city. and now I need dashed underline to a name of the province, how to create dashed underline for the name of the cities in qgis?
Here is a workaround for 2.x.
Having a point shape-file with an attribute
city you can label the cities like:
"city" || '\n' || rpad( '-', length("city") + 5, '-')
BEST FIT - additional
lpad (extend to the left) without addition of a distinct value:
"city" || '\n' || rpad('-',length("city"),'-') || lpad('-',length ("city"),'-')
First argument is the city name, then follows a line break, then we us a hypen and extend (
lpad) it with the length of the city names (
length("city") and/or add a distinct value to stretch the concatenation of hyphens.
EDIT - Using other Unicode characters
You could also use Unicode symbols directly (see https://gis.stackexchange.com/a/90126). Using a
fullwidth hyphen-minus from http://jkorpela.fi/dashes.html (lowermost entry in the first column of the table), the dashed line looks even better. Just copy/paste it in the Expression Dialog. I've shortened it a little bit (
"city" || '\n' || rpad('－',length("city")-2, '－')
Label lookalike with
katakana-hiragana double hyphen:
Additionally you have to decrease the line height in the
Labels > Formatting. So the dash line is closer to the city name. Also use
Alignment to center both lines.
Usage in the Layer Properties:
I think you have to play around a little bit with the distinct value for stretching the concatenation of hyphens.
If there is an attributes that distinguish if the city is a capital or not then you can use
In my case I have an attribute table as follows:
Rule-based labeling in this case:
Result (cities which are not capitals have a normal underline (defined within in the label settings):