I'm trying to label only selected features with an expression using PyQgis and the PAL functions, but I don't find any example and the API don't help me a lot (or I don't found it). My Qgis version is 2.14
This is an extract of my code:
from PyQt4.QtGui import QColor layer = iface.activeLayer() palyr = QgsPalLayerSettings() palyr.readFromLayer(layer) palyr.enabled = True palyr.bufferDraw= True palyr.bufferColor= QColor("white") palyr.bufferSize = 1 palyr.scaleVisibility = True palyr.scaleMax=2000 palyr.isExpression = True # code is a fieldname. Only show the last 3 letters palyr.fieldName = 'right( code ,3 )' palyr.size = 20 # next 2 lines is for change placement palyr.placement= QgsPalLayerSettings.OverPoint palyr.setDataDefinedProperty(QgsPalLayerSettings.Size,True,True,'8','') # I want to set this expression for label only selected features: "code not like '%000'" # MISSING CODE FOR SET DEFINED LABEL USING EXPRESSION palyr.textColor = QColor("red") palyr.drawLabels = True palyr.writeToLayer(layer) iface.mapCanvas().refresh()
I can run this code without errors, but I don't know how to set expression for defined data features.