1

"symbols()" is no longer available in QGIS 3.0 and replaced by "QgsRenderContext& context" method, but I do not find the correct way to write this instruction.

from PyQt5.QtGui import *

lyr=iface.activeLayer()
symbols = lyr.renderer().symbols()
sym = symbols[0]
sym.setColor(QColor.fromRgb(255,0,0))

lyr.triggerRepaint()

1 Answer 1

6

You need to change

symbols=lyr.renderer().symbols()

to

symbols = lyr.renderer().symbols(QgsRenderContext())

and everything will work fine.

2
  • Thank you for your quick response. However, “symbols()” is no longer available in qgis3.0 and replaced by “QgsRenderContext& context” method, but I do not find the correct way to write this instruction. from PyQt5.QtGui import * lyr=iface.activeLayer() symbols = lyr.renderer().symbols() sym = symbols[0] sym.setColor(QColor.fromRgb(255,0,0)) lyr.triggerRepaint()
    – ennine
    Commented May 17, 2018 at 13:21
  • 1
    @ennine I have edited my answer. Hope this answers your edited question.
    – Asad Abbas
    Commented May 17, 2018 at 14:08

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.