I'm trying to get color values from layers inserted into canvas. I used this code but it seems that I'm doing something wrong:
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
sym = layer.rendererV2().symbols()[0]
fill = QgsSimpleFillSymbolLayerV2().fillColor()
p=fill.getRgb()
print(p)
I always get (0,0,255,255) as a result.
Also this is how it looks Layer properties from one of the polygones in canvas.
Is there any way or code to do this right?
I would also like to add that second fill color is added using this code:
sym = layer.rendererV2().symbols()[0]
fill = QgsSimpleFillSymbolLayerV2()
fill.setFillColor(QColor.fromRgb(result[0], result[1], result[2]))
sym.appendSymbolLayer(fill)
[0]
which returnsQgsSimpleFillSymbolLayer
object. And you need append fill toQgsFillSymbol
object. So use.symbols()
without index. Hope this helps. Also next time please ask different question in separate posts, and not editing the existing one, thanks ;)