I am currently working on a project in which I need to turn on the "RESULT_PRE"
field label so this is the code but the field holds decimal values and I want to give a precision of 3 digits. How can I do that?
from qgis.core import QgsProject
from qgis.core import *
from qgis.utils import iface
from qgis.core import QgsEditorWidgetSetup,QgsField
from qgis.core import QgsPalLayerSettings, QgsTextFormat
# Get the active layer
layer = iface.activeLayer()
layer.setLabelsEnabled(True)
label_Settings = QgsPalLayerSettings()
label_Settings.fieldName = "RESULT_PRE"
# Optional: Set label formatting (e.g., font, size, color)
text_format = QgsTextFormat()
text_format.setFont(QFont("Arial", 12)) # Set font and size
label_Settings.setFormat(text_format)
# Enable labelling for the layer
layer.setLabeling(QgsVectorLayerSimpleLabeling(label_Settings))
# Refresh the layer to apply the changes
layer.triggerRepaint()