Skip to main content
added 41 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95

A Python correction to get your issues (moreover, was too long to get a minimum C++ project to debug ;) )

layer = iface.activeLayer()

layerRenderer= layer.renderer()
mSingleRenderer = QgsSingleSymbolRenderer.convertFromRenderer(layerRenderer)
symbol# No need to instantiate here
#symbol = QgsMarkerSymbol()

style = {
    "name": "square",
    "color": "yellow"
}
# Issue 1: you create a symbol but do not assign it
# (not void function, it returns a new element)
new_sym = symbolQgsMarkerSymbol.createSimple(style)
# Commented as it was already working with above code
# symbol.setColor(QColor(255,255,255));
mSingleRenderer.setSymbol(new_sym)
# Issue 2: Forgot to reassign the newly created renderer to your layer
layer.setRenderer(mSingleRenderer)
layer.triggerRepaint()

# Did not test, commented so can be tested "standalone" in PyQGIS
# mLayerTreeView.refreshLayerSymbology(layer.id())

A Python correction to get your issues (moreover, was too long to get a minimum C++ project to debug ;) )

layer = iface.activeLayer()

layerRenderer= layer.renderer()
mSingleRenderer = QgsSingleSymbolRenderer.convertFromRenderer(layerRenderer)
symbol = QgsMarkerSymbol()

style = {
    "name": "square",
    "color": "yellow"
}
# Issue 1: you create a symbol but do not assign it
# (not void function, it returns a new element)
new_sym = symbol.createSimple(style)
# Commented as it was already working with above code
# symbol.setColor(QColor(255,255,255));
mSingleRenderer.setSymbol(new_sym)
# Issue 2: Forgot to reassign the newly created renderer to your layer
layer.setRenderer(mSingleRenderer)
layer.triggerRepaint()

# Did not test, commented so can be tested "standalone" in PyQGIS
# mLayerTreeView.refreshLayerSymbology(layer.id())

A Python correction to get your issues (moreover, was too long to get a minimum C++ project to debug ;) )

layer = iface.activeLayer()

layerRenderer= layer.renderer()
mSingleRenderer = QgsSingleSymbolRenderer.convertFromRenderer(layerRenderer)
# No need to instantiate here
#symbol = QgsMarkerSymbol()

style = {
    "name": "square",
    "color": "yellow"
}
# Issue 1: you create a symbol but do not assign it
# (not void function, it returns a new element)
new_sym = QgsMarkerSymbol.createSimple(style)
# Commented as it was already working with above code
# symbol.setColor(QColor(255,255,255));
mSingleRenderer.setSymbol(new_sym)
# Issue 2: Forgot to reassign the newly created renderer to your layer
layer.setRenderer(mSingleRenderer)
layer.triggerRepaint()

# Did not test, commented so can be tested "standalone" in PyQGIS
# mLayerTreeView.refreshLayerSymbology(layer.id())
added 66 characters in body
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95

A Python correction to get your issues (moreover, was too long to get a minimum C++ project to debug ;) )

layer = iface.activeLayer()

layerRenderer= layer.renderer()
mSingleRenderer = QgsSingleSymbolRenderer.convertFromRenderer(layerRenderer)
symbol = QgsMarkerSymbol()

style = {
    "name": "square",
    "color": "yellow"
}
# Issue 1: you create a symbol but do not assign it
# (not void function, it returns a new element)
new_sym = symbol.createSimple(style)
# Commented as it was already working with above code
# symbol.setColor(QColor(255,255,255));
mSingleRenderer.setSymbol(new_sym)
# Issue 2: Forgot to reassign the newly created renderer to your layer
layer.setRenderer(mSingleRenderer)
layer.triggerRepaint()

# Did not test, commented so can be tested "standalone" in PyQGIS
# mLayerTreeView.refreshLayerSymbology(layer.id())

A Python correction to get your issues

layer = iface.activeLayer()

layerRenderer= layer.renderer()
mSingleRenderer = QgsSingleSymbolRenderer.convertFromRenderer(layerRenderer)
symbol = QgsMarkerSymbol()

style = {
    "name": "square",
    "color": "yellow"
}
# Issue 1: you create a symbol but do not assign it
# (not void function, it returns a new element)
new_sym = symbol.createSimple(style)
mSingleRenderer.setSymbol(new_sym)
# Issue 2: Forgot to reassign the newly created renderer to your layer
layer.setRenderer(mSingleRenderer)
layer.triggerRepaint()

# Did not test, commented so can be tested "standalone" in PyQGIS
# mLayerTreeView.refreshLayerSymbology(layer.id())

A Python correction to get your issues (moreover, was too long to get a minimum C++ project to debug ;) )

layer = iface.activeLayer()

layerRenderer= layer.renderer()
mSingleRenderer = QgsSingleSymbolRenderer.convertFromRenderer(layerRenderer)
symbol = QgsMarkerSymbol()

style = {
    "name": "square",
    "color": "yellow"
}
# Issue 1: you create a symbol but do not assign it
# (not void function, it returns a new element)
new_sym = symbol.createSimple(style)
# Commented as it was already working with above code
# symbol.setColor(QColor(255,255,255));
mSingleRenderer.setSymbol(new_sym)
# Issue 2: Forgot to reassign the newly created renderer to your layer
layer.setRenderer(mSingleRenderer)
layer.triggerRepaint()

# Did not test, commented so can be tested "standalone" in PyQGIS
# mLayerTreeView.refreshLayerSymbology(layer.id())
Source Link
ThomasG77
  • 31.2k
  • 1
  • 55
  • 95

A Python correction to get your issues

layer = iface.activeLayer()

layerRenderer= layer.renderer()
mSingleRenderer = QgsSingleSymbolRenderer.convertFromRenderer(layerRenderer)
symbol = QgsMarkerSymbol()

style = {
    "name": "square",
    "color": "yellow"
}
# Issue 1: you create a symbol but do not assign it
# (not void function, it returns a new element)
new_sym = symbol.createSimple(style)
mSingleRenderer.setSymbol(new_sym)
# Issue 2: Forgot to reassign the newly created renderer to your layer
layer.setRenderer(mSingleRenderer)
layer.triggerRepaint()

# Did not test, commented so can be tested "standalone" in PyQGIS
# mLayerTreeView.refreshLayerSymbology(layer.id())