I am creating a QgsVectorLayer in a plugin and loading it into the map. I would like to set the labelling parameters while I'm doing that. I've followed several examples found here and here, but my labels aren't being displayed. When I go to the labelling tool none of the settings are as I've specified.
def finalize(self): self.vl.commitChanges() self.vl.updateExtents() QgsMapLayerRegistry.instance().addMapLayer(self.vl) self.setDisplayProperties() def setDisplayProperties(self): palyr = QgsPalLayerSettings() palyr.readFromLayer(self.vl) palyr.enabled = True #this works palyr.fieldName = 'label' #this works palyr.placement = QgsPalLayerSettings.OverPoint #?? palyr.placementFlags = palyr.placementFlags or QgsPalLayerSettings(BelowLine) # not working palyr.fontSizeInMapUnits = False palyr.textFont.setPointSize(4.6) #results in 4 - seems to be integer only palyr.textColor = QColor(68,92,249) #this works palyr.writeToLayer(self.vl)
I've tried calling setDisplayProperties at every slot in the finalize procedure with the same result every time. I've also tried with and without various settings.