Setting color of Qgs Symbol to an expression or variable

Issue

This Content is from Stack Overflow. Question asked by Nidal Barada

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.



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?