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

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

| improve this answer | |
  • 1
    Thank you ! Very helpfull! – Valentin L. Jun 24 '19 at 15:20
  • 1
    Answer with explanation is worth more than just code that solves the problem. – TomazicM Jun 24 '19 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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