Setting color of Qgs Symbol to an expression or variable

Viewed 20

I'm working with QgsSymbolLayer and I want to set the stroke color to an expression (@symbol_color) but I can't seem to figure it out. And the documentation doesn't talk about using expressions for it. I basically want to do what is in the photo below but with code

enter image description here

I have my symbol here:

symbol = QgsFillSymbol.createSimple({'color' : '15,0,43,255', 'outline_color' : 'Map : @sourceSymbol', 'outline_wdith' : '125' })

but have no idea how to change it to expression.

I can manipulate the symbol like this:

symbol.symbolLayers()[0].setStrokeColor(Qcolor)

but setStrokeColor takes a QColor.

Edit 1:

I now understand that this should be done using setDataDefinedProperty but

symbol.symbolLayers()[0].setDataDefinedProperty('outline_color','@sourceSymbol')

gives an error of expected str. What is self in this case?

0 Answers
Related