1

I have a polygon vector layer and I want to style it within a processing script. Part of the code creates a categorized symbology for my layer but I cannot find a reference online on how to access the properties of the stroke/border. I have checked the documentation here and I can only find setColor and setOpacity functions which I have used.

    scenarios = {}
    for i, fld in enumerate(fld_names):
        #attribute_value = (color, label)
        scenarios[fld] = (colors[i%2], fld)

    categories = []
    for attr, (color,label) in scenarios.items():
        symbol = QgsSymbol.defaultSymbol(lyr.geometryType())
        symbol.setColor(QtGui.QColor(color))
        #symbol.setOpacity(0.5)
        category = QgsRendererCategory(attr, symbol, label)
        categories.append(category)

    renderer = QgsCategorizedSymbolRenderer('SCENARIO', categories)
    lyr.setRenderer(renderer)
    lyr.setOpacity(.5)
    lyr.triggerRepaint()
1

The setStrokeColor() method is found in the QgsSymbolLayer properties which in your case would be added by using:

symbol.symbolLayer(0).setStrokeColor(QColor(color))
  • @strythe - Most welcome, glad it helped :) – Joseph May 2 at 9:07

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.