Skip to main content
corrected spelling
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        layer.renderer().setOpacity(0.5)

    layer.triggerRepaint()

I tested it in QGIS. See next images (raster layer has a different projection but the transparency was also assigned):

enter image description here

enter image description here

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        layer.renderer().setOpacity(0.5)

I tested it in QGIS. See next images (raster layer has a different projection but the transparency was also assigned):

enter image description here

enter image description here

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        
    else:
        layer.renderer().setOpacity(0.5)

    layer.triggerRepaint()

I tested it in QGIS. See next images (raster layer has a different projection but the transparency was also assigned):

enter image description here

enter image description here

deleted 83 characters in body
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        layer.renderer().setOpacity(0.5)

I tested it in QGIS. See next imageimages (raster layer has a different projection but the transparency was also assigned):

enter image description here

enter image description here

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        layer.renderer().setOpacity(0.5)

I tested it in QGIS. See next image:

enter image description here

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        layer.renderer().setOpacity(0.5)

I tested it in QGIS. See next images (raster layer has a different projection but the transparency was also assigned):

enter image description here

enter image description here

deleted 83 characters in body
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        print "Call function for QgsRasterLayer"layer.renderer().setOpacity(0.5)

I tested it in QGIS. See next image:

enter image description here

You can modify the above code for including QgsRasterLayer objects too.

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        print "Call function for QgsRasterLayer"

I tested it in QGIS. See next image:

enter image description here

You can modify the above code for including QgsRasterLayer objects too.

The problem is that 'QgsVectorLayer' objects have not attribute 'renderer'. This kind of method is for raster layers. If you want to change the transparency of QgsVectorLayer objects you have to use the method: 'setLayerTransparency(int)'; located in QgsVectorLayer class.

Next code works for these kind of objects:

mc=iface.mapCanvas()
 
layers=[]

n = mc.layerCount()

for i in range(n):
    layers.append(mc.layer(i))

for layer in layers:
    
    if layer.type() == 0: #QgsVectorLayer
        layer.setLayerTransparency(95)
        layer.triggerRepaint()
    else:
        layer.renderer().setOpacity(0.5)

I tested it in QGIS. See next image:

enter image description here

added 15 characters in body
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82
Loading
added 121 characters in body
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82
Loading
added 2 characters in body
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82
Loading
Add more information
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82
Loading
Source Link
xunilk
  • 30.2k
  • 4
  • 43
  • 82
Loading