[Qgis-user] Labels not visible when setting them programmatically.

Casper Børgesen (CABO) CABO at NIRAS.DK
Wed Apr 1 04:25:08 PDT 2015


I'm trying to programmatically set and enable labelling on a layer using Python in QGis 2.9.0.

        label = QgsPalLayerSettings()
        label.readFromLayer(myLayer)

        label.enabled = True
        label.fieldName = 'myField'

        # Just to change something clearly visible.
        label.textColor = QColor(255,0,0,255)

        label.writeToLayer(myLayer)

This doesn't enable labelling, but if I enter the Layer Properties on myLayer, everything looks okay and when pressing Apply, the labels become visible.

Is there something I need to set to avoid having to manually click Apply to get the labels visible?

Calling iface.mapCanvas().refresh() afterwards doesn't work.


Regards, Casper
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20150401/55bb2563/attachment.html>


More information about the Qgis-user mailing list