[Qgis-developer] change to new symbology and set symbol transparency + color

Martin Dobias wonder.sk at gmail.com
Mon Jul 4 10:38:25 EDT 2011


Hi Michiel

On Mon, Jun 20, 2011 at 10:05 PM, Michiel Faber <fabermichiel at planet.nl> wrote:
> I wrote a simple script that generates >50 maps (png) automatically from
> shapefiles.
> But i want to finetune the proces and make the map more appealing.
> For this i need to change the symbol transparency. But i haven't found a
> way to do it. sym.setTransparency(75) doesn't work.
>
> Furthermore, i want to change the color of the symbols. I can change the
> inner part of the symbol, but not the edge. Whatever i do, it stays
> yellow (of all colors). The strange thing is that the edge of the
> symbols in the legend do change to the color i want (and the color of
> the symbols on the legend and map if i want to).
> Swapping the lines so renderer.addSymbol is last didn't solve the issue
>
> I believe i am still working with the old symbology as i have not found
> a way to move over to the new symbology using PyQgis. In the cookbook is
> only a reference to check what you use, not to switch.

Yes you are using old symbology. New symbology classes all contain
"V2" in their name: QgsSymbolV2 etc. It is highly recommended to use
new symbology since the old symbology will be removed in 2.x release
series.

I haven't tried the following code yet, but something like this should work:

layer.setRendererV2( renderer )
layer.setUsingRendererV2( True )
layer.setRenderer( None )

First line sets new symbology renderer (any instance of
QgsFeatureRendererV2 subclass), second line tells the vector layer
that new symbology will be used instead of old symbology. Final line
deletes the associated old symbology renderer.

Regards
Martin


More information about the Qgis-developer mailing list