Page 9 sur 18
Labeling
Usual labels
project = QgsProject.instance() myLayers = QgsVectorLayer(myPath + 'myLayers/myLayers.shp', 'myLayers', 'ogr') project.addMapLayer(myLayers) myLayerLabelSettings = QgsPalLayerSettings() myLayerLabelSettings.fieldName = 'name' myLayerLabelSettings.enabled = True myLayerText = QgsTextFormat() myLayerText.setFont(QFont('Verdana', 8)) myLayerText.setSize(8) myLayerLabelSettings.setFormat(myLayerText) myLayerSettings = QgsVectorLayerSimpleLabeling(myLayerLabelSettings) myLayers.setLabeling(myLayerSettings) myLayers.setLabelsEnabled(True) myLayers.triggerRepaint() iface.mapCanvas().refresh() time.sleep(0.5)