In QGIS 3.22 use the drag and drop designer to set up form.
The form are used for data entry but also with the Identify Features tool or with the attribute table form view to review data as form let you choose witch field to display, organise them in a logical manner and use widget to change how the value are displayed.
This work perfectly well in edit mode but when just interrogating data (so not in edit mode) some widget displays the attribute in medium grey on a light grey background (for exemple the drop down of a Value Map widget) while other have black text (for exemple text edit widget). This give a low legibility to the grey text attribute and create a false hierarchy to the point that some user may get the impression that the grey text is just filler text rather than an actual attribute they need to review (after all it is common practice on the web to pre-fill form with text like "username" and "password" to let you know what to type in).
See below what I mean:
- edit mode on
- edit mode off
I think that being able to display attribute in a consistant way will provide a better experience for user so my question is: How to change the font color of the displayed attribute in a form when not in edit mode? (I'm avare that it's possible to change the label color and font but this has no impact on the attribute value)
1 Answer 1
I guess this will be a bit tricky to solve without a bit of effort. The only two things that come to my mind is using a ui-file designed in QT-Designer instead of the drag/drop form or a custom python function in the attribute form.
The second idea is described here:
Example Code for a Field "Name" as Combobox in the Form:
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
nameField = None
myDialog = None
# based on https://woostuff.wordpress.com/2011/09/05/qgis-tips-custom-feature-forms-with-python-logic/
def openForm(dialog,layerid,featureid):
global myDialog
myDialog = dialog
global nameField
print(dialog.children())
nameField = dialog.findChild(QComboBox,"Name")
changeColor()
def changeColor():
nameField.setStyleSheet("color: rgb(255, 0, 0);")
The downside of this approach is that you have to activate Macros in QGIS what I personally don't like due to security reasons, especially when opening QGIS projects from someone else.
Update1: If you want to style all Comboboxes in your form you can use:
from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
# based on https://woostuff.wordpress.com/2011/09/05/qgis-tips-custom-feature-forms-with-python-logic/
def openForm(dialog,layerid,featureid):
all_combos = dialog.findChildren(QComboBox)
for combo in all_combos:
combo.setStyleSheet("color: rgb(255, 0, 0);")
-
I updated the answer above to show how to style all comboboxes in the dialogThomas B– Thomas B2023年12月06日 15:21:23 +00:00Commented Dec 6, 2023 at 15:21
-
1You python solution work perfectly well, as the project will only by used internally activating macro for this one project will be acceptable for userJ.R– J.R2023年12月06日 15:39:57 +00:00Commented Dec 6, 2023 at 15:39