8

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.)

8

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%.

  • Is it possible to do the same when you have also vector layers? Like do it only for selected layers, or for layers inside one same group? – Victor Sep 4 '15 at 14:26
  • this doesn't seem to work anymore in 2.8.2, i see a rendererV2 in the docs instead of renderer, but it doesnt have the setOpacity method :( – chrismarx Jan 18 '16 at 0:03
  • i see this ticket that would suggest layer groups could do this, but i don't see how either - trac.osgeo.org/qgis/ticket/557 – chrismarx Jan 18 '16 at 0:06
  • For GQIS3 replace first line w: for layer in [layer for layer in QgsProject.instance().mapLayers().values()]: per this: gis.stackexchange.com/questions/273576/… – andrew Aug 20 '18 at 18:18
4

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"

2

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

2

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

  • no because that will copy over everthing else, including the symbology/colours/view extents. – Theo F Nov 6 '17 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.