[Qgis-user] How to set field alias expression in PyQGIS ?
Yann Voté
ygversil at lilo.org
Thu Apr 8 06:40:40 PDT 2021
Hi list,
I'm stuck at configuring field alias expressions programmatically,
didn't found helplful documentation, so any help would be appreciated.
What I want is the field label in form to looks like "Code (last used:
XXX)" where XXX is, well, the last used code. And this is easily done in
GUI, in the layer properties, form tab (feature introduced in 3.14).
But I want to do it programmatically in PyQGIS. What I tried so far is
the following two lines
>>> prop = QgsProperty.fromExpression("format('Code (last used: %1)',
maximum(code))", isActive=True)
>>>
layer.editFormConfig().dataDefinedFieldProperties('code').setProperty(QgsEditFormConfig.Alias,
prop)
But then the following command
>>>
layer.editFormConfig().dataDefinedFieldProperties('wetland_code').hasProperty(QgsEditFormConfig.Alias)
still returns False.
What am I missing ?
Thx a lot!
--
Yann Voté - ygversil at lilo.org
More information about the Qgis-user
mailing list