1

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

asked Apr 17 at 12:52
0

1 Answer 1

3

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.

enter image description here

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

enter image description here

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:

enter image description here

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):

enter image description here

Now, you get a separate row with this entry:

enter image description here

answered Apr 18 at 16:32
2
  • Worked perfectly! Thank you very much! Commented 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 it Commented Apr 23 at 8:24

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.