How can I change the fill border color for vector layers? I want to make it Transparent Fill. I have 1000 shapefiles, and want them to be transparent fill. Is there a way to do it by Python Script?

  • 1
    What kind of vector layers? Are they all polygons, lines, points, or a mixture of all three?
    – Joseph
    Commented Dec 7, 2016 at 10:32

3 Answers 3


While setting the outline colour for vector layer, set opacity to '0', then outline will be transparent in Layer Properties -> Style, then save your layer style the layer style as .qml file and apply the same style to all layers. To apply layer style for layer using following codes in python console

# create vector layer object
vector_file = '/path/to/vetor.shp'
vector = QgsVectorLayer(vector_file, 'vector name', 'ogr')
# Adds vector layer to registry
# Set the layer style from qml file
# Refresh the canvas to make the change in layer style visible

Use some loop to repeat do the same for multiple layers. See here to load multiple layers.

  • This is a good solution if all layers should have the exact same style. My guess is that the layers will have their own particular style and the OP just wants to set the outline to be transparent. Nevertheless, +1 ;)
    – Joseph
    Commented Dec 7, 2016 at 13:32
  • Thanks !it works too. but i used some other code for making it transparent :)
    – User18
    Commented Dec 8, 2016 at 6:58

To Fill Layer background Transparent .Use code as follows :

   from PyQt4 import QtGui      
   layer = iface.addVectorLayer("path_to_vector_layer", "layer_name", "ogr") 
   myVectorLayer = iface.activeLayer()
   myRenderer  = myVectorLayer.rendererV2()

   if myVectorLayer.geometryType() == QGis.Polygon:

       mySymbol1 = QgsFillSymbolV2.createSimple({'color':'#ffffff', 

It works for me :)


For PyQGIS 3:

my_vector_layer = iface.activeLayer()
my_renderer = my_vector_layer.renderer()

my_layer_geom_type = my_vector_layer.geometryType()
if my_layer_geom_type == QgsWkbTypes.PolygonGeometry:
    my_symbol1 = QgsSymbol.defaultSymbol(my_layer_geom_type)
    fill_layer = QgsSimpleFillSymbolLayer.create(
            'color': '255,255,255,255',
            'outline_color': '0,0,0,255',
            'outline_width': '0.6'
    my_symbol1.changeSymbolLayer(0, fill_layer)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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