TransWikia.com

How to set the transparency for multiple layers or add a global transparancy preference?

Geographic Information Systems Asked by Samir on December 10, 2020

How can I set the transparency to 27 % for all 245 layers in QGIS? The only way I know of is by right clicking on the layer name, selecting Properties, then Transparency and then moving the transparency slider left or right.

a

This is simple enough. But this is only good for up to 10 layers maybe. What if you have 245 layers like I do? Do you just keep on repeating the process? Now surely, there there must be a way to apply this to all 245 layers at once!?

b

Alternatively, is there a global transparency preference setting I can add in so that when I add new layers they automatically get 27 % transparency?

The QGIS online documentation mentions something about exporting your transparency setting to a file for a later use.

As you can see this is quite easy to set custom transparency, but it
can be quite a lot of work. Therefore you can use the button Export to
file to save your transparency list to a file. The button Import from
file loads your transparency settings and applies them to the current
raster layer.

This seems like a useful feature. But I don’t think this is what I’m looking for.

I tried selecting multiple layers in the table of contents and then right click and select Properties and set the transparency level, apply changes and click OK. It applied the changes, but only to the last layer in the selection, the one I right clicked on. None of the other layers in the selection were affected. (This could be a bug actually.)

4 Answers

A little python script like this would do it

for layer in iface.legendInterface().layers():
   layer.renderer().setOpacity(0.2)

Just copy and paste that into the python console (which is shown via Plugins->Python console) and hit enter twice. The script will loop through all layers and set their opacity to 20%.

For QGIS 3.x you need a slightly different Python script because the API has changed significantly:

layers = qgis.core.QgsProject.instance().layerTreeRoot().layerOrder()
for layer in layers:
    layer.setOpacity(0.2)
# Redraw the layers so you can see the effect
iface.mapCanvas().refreshAllLayers()

Answered by ndawson on December 10, 2020

Another option, requiring no python, is to simply edit you project file.

Raster layer transparency is set with: rasterrenderer opacity="1"

You can open your project file .qgs in a text editor and find and replace: rasterrenderer opacity="1" With: rasterrenderer opacity="0.73"

Answered by HeikkiVesanto on December 10, 2020

You may use this QGIS Processing script to set transparency for a specific group: https://github.com/jkall/qgis-processing-scripts/blob/master/set_transparency_for_group.py

Answered by joskal on December 10, 2020

The easiest way to do this is by using layer styles. Just set the transparency of a single layer to 27% and copy/paste the style to all other layers. You can paste a style to multiple layers at once.

See also:

http://hub.qgis.org/issues/14931

Answered by eclipsed_by_the_moon on December 10, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP