1

I'm trying to set up the colour of a QgsSimplerMarkerSymbolerLayer.

Here is my code :

sites=iface.activeLayer()
single_symbol_renderer=sites.renderer()
symbol=single_symbol_renderer.symbol()
symbol.setSize(4)
prop = QgsProperty()
prop.setField("Couleur")
pc = QgsPropertyCollection('Color')
pc.setProperty(4, prop)
marker_symb = QgsSimpleMarkerSymbolLayer()
marker_symb.setDataDefinedProperties(pc)
sites=QgsSimpleMarkerSymbolLayer(marker_symb)

But it still not working, any help ?

1 Answer 1

3

try with this:

# Point Layer
layer = QgsProject.instance().mapLayersByName('PointLayer')[0]

renderer = QgsMarkerSymbol()

# Use is the column name when I have hexadecimals colors
renderer.symbolLayers()[0].setDataDefinedProperty(QgsSymbolLayer.PropertyFillColor, QgsProperty.fromField("Couleur") );
layer.setRenderer(QgsSingleSymbolRenderer(renderer))

layer.triggerRepaint()

Based on this other response from me

2
  • 1
    Thank you ! Very helpfull! Commented Jun 24, 2019 at 15:20
  • 1
    Answer with explanation is worth more than just code that solves the problem.
    – TomazicM
    Commented Jun 24, 2019 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.