2

How do i change the Stroke Style of a simple fill with python ? Here is a picture that i want to change ? enter image description here

Here is my code :

    processing.run('native:buffer', {"INPUT": delta, "DISTANCE":QgsProperty.fromExpression("bande"), "OUTPUT": "memory"})
    blayer=QgsVectorLayer("MultiPolygon?crs=epsg:2154", "Bande Etude", "memory")
    QgsProject.instance().addMapLayer(blayer)
    blayer_feat= blayer.getFeatures()
    blayer.startEditing()
    j=0
    for feat in blayer_feat :
      blayer.changeAttributeValue(feat.id(), 1, delta_t[j])
      j=j+1
    target_field = 'delta_t'

    myRangeList = []

    symbol = QgsSymbol.defaultSymbol(blayer.geometryType())
    symbol.setColor(QColor("#f7fbff"))
    symbol.setOpacity(0.6)
    #symbol(0).setStrokeStyle(Qt.PenStyle(Qt.NoPen))
    myRange = QgsRendererRange(0, 10.0, symbol, '0 a 10')
    myRangeList.append(myRange)

    symbol = QgsSymbol.defaultSymbol(blayer.geometryType())
    symbol.setColor(QColor("#08306b"))
    symbol.setOpacity(0.6)
    myRange = QgsRendererRange(10.1, 100.0, symbol, '10 a 100')
    myRangeList.append(myRange)

    myRenderer = QgsGraduatedSymbolRenderer(target_field, myRangeList)
    myRenderer.setMode(QgsGraduatedSymbolRenderer.Custom)

    blayer.setRenderer(myRenderer)
    blayer.setFeatureBlendMode(QPainter.CompositionMode_Darken

I've tried a line code like : symbol(0).setStrokeStyle(Qt.PenStyle(Qt.NoPen)) but it does not work.

1

You're close, you need to use symbolLayer(0) and not symbol(0):

...
symbol.setOpacity(0.6)
symbol.symbolLayer(0).setStrokeStyle(Qt.PenStyle(Qt.NoPen))
...

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.