I working with QGIS 3.20. I want to write a PyQGIS script to automate switching the field used for labeling in numerous layers. Currently the layers are labeled from values of a field that is different for each layer.
I thought I will follow this procedure:
- Get the field name that is currently used for labeling (say field
"X"
) in a variable - Add a new field
"Label"
and populate its values according to the values in field"X"
- Set the labeling field to the
"Label"
field
I know how to do number 2 and I am looking for a way to do number 1 and 3. So my questions are: how do I get the labeling field name (to store in a variable)? How do I change the labeling field?
In the UI this is the labeling field I want to access and change (however its name is different for each layer):
What would be the way to go?