2

I'm trying to set the Width of the lake's contours to zero or change the color to light blue, since the I dont want to see the black outline. The vector file is a Polygon (MultiPolygon) named vlayer2 and I have tried the following commands:

vlayer2.setStrokeWidth(0)
vlayer2.setStrokeColor([49,179,245])
vlayer2.setWidth(0)

But I always get the message: ''AttributeError: 'QgsVectorLayer' object has no attribute '....' ''

enter image description here

1 Answer 1

3

The methods you are trying to use belong to the QgsSimpleMarkerSymbolLayer class. You need to access the symbol layer of your vector layer's renderer before you can call these methods.

The following should work for you to set the stroke color, bearing in mind that you need to pass a QColor object to this method:

vlayer2.renderer().symbol().symbolLayer(0).setStrokeColor(QColor(49, 179, 245))
vlayer2.triggerRepaint()

Alternatively, you could set the stroke style to 'No Pen'. Setting the width to 0 will still give a 'hairline' width.

vlayer2.renderer().symbol().symbolLayer(0).setStrokeStyle(Qt.PenStyle.NoPen)
vlayer2.triggerRepaint()

I thoroughly recommend checking out the PyQGIS Developer Cookbook which contains many useful examples.

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.