2

I’m trying to remove the “Bande 1” label that appears in the raster legend in QGIS 3.40 (Bratislava).

This issue was already mentioned here: How to turn off QGIS legend band number by default?

The suggested solution works manually, but I’m looking for a way to automate it, since I have many rasters and I’m preparing an atlas that I’ll need to reuse for future projects.

Has anyone found a way to disable this label automatically either through a PyQGIS script or a style (.qml) setting? I couldn’t find any option for it in the raster layer properties.

Thanks a lot for your help!

1 Answer 1

3

You can use a PyQGIS script:

layout_name = "Layout 4" #Adjust to match the name of your layout

#Find the layout object by its name
lm = QgsProject.instance().layoutManager().layoutByName(layout_name)

#List legends, pick the first (0) one.
legend = [x for x in lm.items() if isinstance(x, QgsLayoutItemLegend)][0]

#For each child in the legend, if it is a Legend Node, 
#  change its label to a whitespace
model = legend.model()
children = list(model.children())
for child in children:
    if isinstance(child, QgsSimpleLegendNode):
        #print(child)
        #<QgsSimpleLegendNode: "Band 1: Layer_1 (Palette)">
        #<QgsSimpleLegendNode: "Band 1 (Gray)">
        child.setUserLabel(" ")

enter image description here

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.