0

I'm trying to set some labels and styles for some vector layers that are loaded programatically from a Spatialite database. I have the following code, which returns no error, and includes the changes in the .qgis file, but does not show on the canvas:

uri = QgsDataSourceURI()  
uri.setDatabase(database_path)
uri.setDataSource('', table_name, 'geometry')
layer = QgsVectorLayer(uri.uri(), display_name, 'spatialite')
QgsMapLayerRegistry.instance().addMapLayer(layer)

layer.setCustomProperty("labeling/enabled", "true")  
layer.setCustomProperty("labeling/fontFamily", "Arial")
layer.setCustomProperty("labeling/fontSize", "10")
layer.setCustomProperty("labeling/fieldName", "source_id")
layer.setCustomProperty("labeling/placement", "2")

How can I get this to work?

1 Answer 1

4

You have to set the custom property that enables labeling in the first place.

layer.setCustomProperty("labeling", "pal")
layer.setCustomProperty("labeling/enabled", True)

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.