Already got it working, using the setLegendSymbolItem() on the renderer:
layer = iface.activeLayer()
renderer = layer.renderer()
symbolItems = renderer.legendSymbolItems()
for symbolItem in symbolItems:
print(symbolItem)
symbol = symbolItem.symbol()
color = symbol.color()
color.setAlpha(255 * 0.8)
symbol.setColor(color)
renderer.setLegendSymbolItem(symbolItem.ruleKey(), symbol)
layer.triggerRepaint()
No clue if it will run in 2.18, expecting not. Hoping you can upgrade.
Raymond
On 05-01-19 13:22, Raymond Nijssen wrote:
Hi Marian,
As I understand you want to set every symbol in your rule based
classification to 80% transparent (instead of the entire layer)?
I tried to write a qgis (v3.4) script but unfortunately it crashes my
qgis. So I hope somebody here can correct it, or maybe you will find the
solution yourself.
I'm doing many prints to see the return values. The crash happens when
in line 18: symbolItem.setSymbol(symbol)
---
layer = iface.activeLayer()
renderer = layer.renderer()
symbolItems = renderer.legendSymbolItems()
print(symbolItems)
for symbolItem in symbolItems:
print('---')
print(symbolItem)
symbol = symbolItem.symbol()
print(symbol)
color = symbol.color()
print(color.name(1))
color.setAlpha(255*0.8)
print(color.name(1))
symbol.setColor(color)
symbolItem.setSymbol(symbol) # !!! this makes qgis crash
layer.triggerRepaint()
---
When crashing, qgis outputs:
QGIS died on signal 11Could not attach to process. If your uid matches
the uid of the target
process, check the setting of /proc/sys/kernel/yama/ptrace_scope, or try
again as the root user. For more details, see /etc/sysctl.d/10-ptrace.conf
ptrace: Operation not permitted.
No thread selected
No stack.
gdb returned 0
Aborted (core dumped)
---
Kind regards,
Raymond
On 04-01-19 22:32, Tudorache, Marian wrote:
Hi,
I have a polygon type vector layer with rule-based style.
I need to change programmatically the layer transparency.
I used the following code:
layer = iface.activeLayer()
layer.setTransparency(80)
layer.triggerRepaint()
This works only if I want to see layers which are under the active one
but it does not work for the features inside active layer.
When there are identical polygons which overlap within active layer, I
can only see the top one. If I select a polygon which is underneath it
is not displayed as selected.
I can make it work if I manually open the layer style and double click
on rule to open Rule properties and set the transparency for the rule.
How can I change the rule transparency programmatically?
Thank you,
Marian
------------------------------------------------------------------------
This electronic message, as well as any transmitted files included in
the electronic message, may contain privileged or confidential
information and is intended solely for the use of the individual(s) or
entity to which it is addressed. If you have received this electronic
message in error please notify the sender immediately and delete the
electronic message. Any unauthorized copying, disclosure or
distribution of the electronic message is strictly forbidden. NAV
CANADA accepts no liability for any damage caused by any virus and/or
other malicious code transmitted by this electronic communication.
Le présent message électronique et tout fichier qui peut y être joint
peuvent contenir des renseignements privilégiés ou confidentiels
destinés à l’usage exclusif des personnes ou des organismes à qui ils
s’adressent. Si vous avez reçu ce message électronique par erreur,
veuillez en informer l’expéditeur immédiatement et supprimez le. Toute
reproduction, divulgation ou distribution du présent message
électronique est strictement interdite. NAV CANADA n’assume aucune
responsabilité en cas de dommage causé par tout virus ou autre
programme malveillant transmis par ce message électronique.
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user
_______________________________________________
Qgis-user mailing list
Qgis-user@lists.osgeo.org
List info: https://lists.osgeo.org/mailman/listinfo/qgis-user
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-user