I have a vector layer with an attribute text field with 3 words (word1, word2 and word3). I want to capitalize the first letter of word1 and word3 in label output. For example if a record has the following words "rio della casa" i want as label "Rio della Casa". I know in QGIS there is the title() statement but it capitalizes the first letter of all the words, so can someone help me to find the right rule for labelling?
You can create a custom function in the Field Calculator to capitalize the first letter of the first and last words. The following function can do what you are looking for:
from qgis.core import * from qgis.gui import * @qgsfunction(args='auto', group='Custom') def upper_word(text_field, feature, parent): split_txt = text_field.split() new_txt = split_txt.title() + ' ' + split_txt + ' ' + split_txt.title() return new_txt
and here how it looks in the Field Calculator:
Then call the function from the custom mene:
Here is the output in the attribute table: