Hi,

I have the same problem when I tried to set labels from a python plugin :

With this code, labels are correctly displayed without having to apply layer properties, but only for points or polygons layers. For lines layers, I have to apply layer properties in order to display labels.
        palLayer = QgsPalLayerSettings()
        palLayer.readFromLayer(self.serpLayer)
        palLayer.enabled = True
        palLayer.fieldName = 'id'
        palLayer.textFont.setPointSize(10)
        palLayer.writeToLayer(self.serpLayer)

With this code, I get the same problem for points, lines and polygons layers :
        self.serpLayer.setCustomProperty('labeling', 'pal')
        self.serpLayer.setCustomProperty('labeling/enabled', 'true')
        self.serpLayer.setCustomProperty('labeling/fieldName', 'id')
        self.serpLayer.setCustomProperty('labeling/fontSize', '10')

self.serpLayer.triggerRepaint() and/or self.iface.mapCanvas().refresh() don't help.

Hope someone can help...

--
Christophe

Le 01/04/2015 14:20, Werner Macho a écrit :
hmm -
well - as the qchainage plugin clearly sets labeling (when enabled)
you could take it and search for the missing piece..
regards
Werner

On Wed, Apr 1, 2015 at 2:19 PM, Casper Børgesen (CABO) <[email protected]> wrote:
No the triggerRepaint() didn't work, just to clarify that I tried that :)

Regards, Casper

-----Original Message-----
From: Werner Macho [mailto:[email protected]]
Sent: 1. april 2015 13:52
To: Casper Børgesen (CABO)
Cc: [email protected]
Subject: Re: [Qgis-user] Labels not visible when setting them programmatically.

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) <[email protected]> wrote:
Hi Werner

Sadly no, it does not.


Regards, Casper

-----Original Message-----
From: Werner Macho [mailto:[email protected]]
Sent: 1. april 2015 13:43
To: Casper Børgesen (CABO)
Cc: [email protected]
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) <[email protected]> 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
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-user


---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com

_______________________________________________
Qgis-user mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/qgis-user

Reply via email to