In my QGIS python plugin, this code triggers a deprecated warning (QgsFeatureRendererV2.symbols() is deprecated) :

myLayer.rendererV2().symbols()[0].changeSymbolLayer(0, mySymbolLayer)

What is the alternative up-to-date way to modify a layer's symbology ? The doc says :

use symbols( QgsRenderContext& context ) instead

but I can't find the correct way to follow that advice...

  • I get this message with QGIS 2.14 and 2.18
    – sigeal
    Commented Jun 30, 2017 at 10:46
  • Could you please edit your question to include how you want to change the symbology of your layer? For QGIS 2.18, I used this post to make symbology changes.
    – Joseph
    Commented Jun 30, 2017 at 11:23
  • Yes, it's the same code as mine, it can be found in many tutorials on the net, and it actually work, it's just that i gives a deprecated warning I would like to get rid of...
    – sigeal
    Commented Jun 30, 2017 at 13:36

1 Answer 1


Here is an answer to my question :

objLayer.rendererV2().symbols2(QgsRenderContext())[0].changeSymbolLayer(0, symbolLayer)

No deprecated warning anymore with this code.

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.