1
layer=iface.activeLayer() 
label=QgsPalLayerSettings()
label.readFromLayer(layer) 
label.enabled=True label.fieldName='NAME'
label.placement= QgsPalLayerSettings.OrderedPositionsAroundPoint
label.labelDistance=2 
label.writeToLayer(layer) 

I want to use label.labelDistance=2 to set it,but it no use. enter image description here

5

It's dist, not labelDistance. This should work:

layer=iface.activeLayer() 
label=QgsPalLayerSettings()
label.readFromLayer(layer) 
...
label.dist=2 # units are millimeters
label.writeToLayer(layer)
|improve this answer|||||
  • How to set the labe of text size and font family ? – zuotianhui Apr 28 '17 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.