I want to achieve changing text color of a dynamic text widget in my attribute form. I got the idea from an example of the QGIS Changelog (3.30). There is a GIF explaining the new feature Dynamic text widgets with current_value support.
I ́ve achieved building the expression but now i want to change the color and the font style (bold, italic etc.). Can you halp me what expressions I have to use for this?
Best
1 Answer 1
Go to layer Properties
> Tab Attributes form
and select the field for which you want to make the setting. For Alias
, click data driven override (icon ɛ
) and use an expression that generates a html-formatted font.
See the following example to format the alias of the field name, based on its content: Red bold prompt if the field is empty, blue italic if the name is not in uppercase and green bold if a name in uppercase is entered.
CASE
When "name" is NULL or "name"='' then '<span style= "color:red; font-weight:bold">' || 'Empty name!' || '</font>'
When left ("name",1) = upper (left ("name",1)) then '<span style= " color:green; font-weight:bold ">' || 'Correct Name format' || '</font>'
Else '<span style = "color:blue; font-style:italic">' || 'Use uppercase for names' || '</font>'
END
To add this label as a separate row (instead of using it in the place of the fieldname), in Attributes Form on the top select Drag and Drop Designer, click the green + icon (Add a new tab or group to the form layout) to add a new container, e.g. called Label. For containter type, choose Row. When created, from the left part, drag and drop the Text Widget entry to the created container:
In the dialog to configure the text widget, you can again use data driven override and paste the same expression as above. When you click OK, the expression will be enclosed in square brackets with % character: [%
(opening) and %]
(closing):
Now, you get a separate row with this entry:
-
Worked perfectly! Thank you very much!delmarzo– delmarzo2025年04月23日 07:59:22 +00:00Commented Apr 23 at 7:59
-
You're welcome. As a new user be informed that this site tries to avoid thank you messages and instead encourages you to accept an answer if it solved the problem (hit the checkmark icon) and/or upvote itBabel– Babel2025年04月23日 08:24:33 +00:00Commented Apr 23 at 8:24