Thursday 20 June 2019

python - QGIS programmatically change outline colour of circles


I have a vector layer with a "Simple Marker" for the style. I see I can create Data Defined properties for both the colour and the outline colours.



In Python, I'm able to change the marker's base colour (for the data defined property), but I can't seem to find how to change the outline's colour.


Here's what I have:


symbols = layer.rendererV2().symbols()
symbol = symbols[0]

expr = 'color_rgba(255,0,0,0)'
symbol.symbolLayer(0).setDataDefinedProperty('color', expr)

# I would expect this to work, but it doesn't
symbol.symbolLayer(0).setDataDefinedProperty('outlineColor', expr)


Any ideas?



Answer



Next code works [but I used 'color_rgba(255,0,0,255)' to avoid complete transparency]; where 'color_border' is the adequate property for color border.


layer = iface.activeLayer()

symbols = layer.rendererV2().symbols()

symbol = symbols[0]


expr = 'color_rgba(255,0,0,255)'
symbol.symbolLayer(0).setDataDefinedProperty('color', expr)

# I would expect this to work, but it doesn't
symbol.symbolLayer(0).setDataDefinedProperty('color_border', expr)

layer.triggerRepaint()

iface.legendInterface().refreshLayerSymbology(layer)

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...