Saturday, 6 October 2018

qgis - How to change the color of a vector layer in pyQGIS?


Is it possible to change the color while adding a vector layer? I have a vector layer with water areas and want to load it with a blue color style. The layer is added with:


QgsMapLayerRegistry.instance().addMapLayer(self.vlayer)


Can I somehow change the color after or while loading?



Answer



you can use something like this:


symbols = self.vlayer.rendererV2().symbols()
symbol = symbols[0]
symbol.setColor(QColor.fromRgb(50,50,250))

Good job!


No comments:

Post a Comment