Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from qgis.core import QgsProject
- from qgis.utils import iface
- def transparency_slider(layers):
- """Add the opacity slider to any new layer added in QGIS."""
- for layer in QgsProject.instance().mapLayers().values():
- if (
- layer.customProperty("embeddedWidgets/count") != 1
- or layer.customProperty("embeddedWidgets/0/id") != "transparency"
- ):
- layer.setCustomProperty("embeddedWidgets/count", 1)
- layer.setCustomProperty("embeddedWidgets/0/id", "transparency")
- else:
- pass
- iface.layerTreeView().refreshLayerSymbology(layer.id())
- def initTransparencySlider():
- """Initialize the transparency slider connection when QGIS is ready."""
- QgsProject.instance().layersAdded.connect(transparency_slider)
- # Also apply to any existing layers on startup
- transparency_slider(QgsProject.instance().mapLayers().values())
- # Add the initialization function to be run when QGIS is ready
- iface.initializationCompleted.connect(initTransparencySlider)
Advertisement
Add Comment
Please, Sign In to add comment