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

Werner Macho werner.macho at gmail.com
Wed Apr 1 04:51:42 PDT 2015


Hi!

I thought maybe it is the
triggerRepaint()

but it was just a guess.

regards
Werner

On Wed, Apr 1, 2015 at 1:48 PM, Casper Børgesen (CABO) <CABO at niras.dk> wrote:
> Hi Werner
>
> Sadly no, it does not.
>
>
> Regards, Casper
>
> -----Original Message-----
> From: Werner Macho [mailto:werner.macho at gmail.com]
> Sent: 1. april 2015 13:43
> To: Casper Børgesen (CABO)
> Cc: qgis-user at lists.osgeo.org
> Subject: Re: [Qgis-user] Labels not visible when setting them programmatically.
>
> Hi,
> does
> https://github.com/mach0/qchainage/blob/master/chainagetool.py
>
> line 150 ff help you?
>
> regards
> Werner
>
> On Wed, Apr 1, 2015 at 1:25 PM, Casper Børgesen (CABO) <CABO at niras.dk> wrote:
>> 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
>>
>>
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-user



More information about the Qgis-user mailing list