Thursday, 17 August 2017

Pause Labeling in QGIS?


Is it possible to pause/stop labeling temporarily in QGIS like in Arcmap for all layers at once?


The label toolbar offers no solution.



Answer



QGIS 3.x


You could use the following code in the Python Console to create a button on the toolbar which toggles the labels for all vector layers:


action = QAction(QIcon(""), "Turn labels" + "\n" + "ON/OFF", iface.mainWindow())
action.setCheckable(True)
iface.addToolBarIcon(action)


def label_control():
for layer in QgsProject.instance().mapLayers().values():
if layer.type() == QgsMapLayer.VectorLayer:
if action.isChecked() == True:
layer.setLabelsEnabled(True)
else:
layer.setLabelsEnabled(False)
layer.triggerRepaint()

action.triggered.connect(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)

Code was based on the question: How to turn on/off all labels of all layers in QGIS.




QGIS 2.18.x


You can use the Deactivate/Active Labels plugin which has a button to switch on/off labels for all layers:


Invert labels


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...