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?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityI 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?
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:
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):
In QGIS 3.12 you find the plugin "Deactivate Active Labels" which offers a neat possibility to toggle labels of all layers. At the time of writing the plugin's GitHub repository was quite young, thus the plugin may not be available or compatible to previous versions of QGIS.