I would like to turn on / turn off all labels of any layer by one klick. Like you can do in ArcGIS according to that post:
Is there a way to turn off all labels in ArcMap without clicking on every layer?
Answer
Not sure if there is an existing option to do this but using a bit of python, we can always create such a function ourselves!
So we could:
- Create a temporary icon on the toolbar which can toggle.
- Create a function which enables/disables labeling for each layer depending on the toggle state of the icon.
- Connect the icon to the function.
The code could look something like this which you can paste into the Python Console:
from PyQt4.QtCore import QObject, SIGNAL
from PyQt4.QtGui import QAction, QIcon
action = QAction(QIcon(""), "Turn labels" + "\n" + "ON/OFF", iface.mainWindow())
action.setCheckable(True)
iface.addToolBarIcon(action)
def label_control():
for layer in QgsMapLayerRegistry.instance().mapLayers().values():
if action.isChecked() == True:
layer.setCustomProperty("labeling/enabled", True)
else:
layer.setCustomProperty("labeling/enabled", False)
layer.triggerRepaint()
QObject.connect(action, SIGNAL("triggered()"), label_control)
# Uncomment line below if you want to remove the icon yourself,
# otherwise it will be removed automatically when you restart QGIS
#iface.removeToolBarIcon(action)
Example:
Couple of layers which have labelling enabled (toggled):
Same layers but with the labels disabled (untoggled):
No comments:
Post a Comment