4

How can I set the number of decimals for QgsPalLayerSettings object? I used the following code (from QGIS Python Programming Cookbook).e

label = QgsPalLayerSettings()
label.readFromLayer(shp)
label.enabled = True
label.fieldName='tmp_Averag'
label.placement= QgsPalLayerSettings.AroundPoint
label.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'8','')
#label.decimals = 2
label.writeToLayer(shp)
QgsMapLayerRegistry.instance().addMapLayers([shp])

I tried to read the API document and I thought

label.decimals = 2

does the job. But it did not work.

1 Answer 1

4

Right, label.decimals is the way to go. You are just missing the

label.formatNumbers = True

instruction, to make QgsPalLayerSettings format numbers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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