Skip to main content
edited tags
Link
Joseph
  • 76.3k
  • 7
  • 172
  • 286
edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Source Link
raosaeedali
  • 707
  • 7
  • 21

Loading labels from Python script in QGIS

Is there a way to add labels of the added layers using python. I've tried these lines of code but no label shows after execution in QGIS 3.0

for layer in QgsProject.instance().mapLayers().values():
    layer.setCustomProperty("labeling/fieldName", "Id" )
    layer.setCustomProperty("labeling/placement", QgsPalLayerSettings.Horizontal)
    layer.setCustomProperty("labeling/predefinedPointPosition", QgsPalLayerSettings.BottomRight)
    layer.setCustomProperty("labeling/fontSize","10" )
    layer.setCustomProperty("labeling/bufferDraw", True)
    layer.setCustomProperty("labeling/enabled","true" )
    layer.triggerRepaint()