I'm working in QGIS, formatting maps in their layout view. I'd like to swiftly and accurately make >50 nearly identical maps using a single layer feature with a large attribute file. Each map would be the same map, except for the field (column of attribute table) whose data is being symbolized in the map layout.

I'd like for the name of the field to be automatically updated and displayed on the map in a label box in layout view (or some analogous text display).

It appears inserting an expression into the label item is the answer to my dilemma but there don't appear to be any expressions which return the name of the field being symbolized within the layer being symbolized. Is this correct?

I have access to ArcGIS desktop and online, should I switch to their programs for this niche functionality? (I'd prefer not if possible haha)

1 Answer 1


You can get the attribute column name of your layer by using a dedicated Python function in the "Function Editor"

@qgsfunction(args='auto', group='Custom')
def getRenderColumnFromLayerName(layer_name, feature, parent, context):
    Get the column name used for category from the layer name
    <h2>Example usage:</h2>
      <li>getRenderColumnFromLayerName(layer) -> 'pop_est'</li>
    layers = QgsProject.instance().mapLayersByName(layer_name)
    layer = layers[0]
    return layer.renderer().classAttribute()

Then, call the function with getRenderColumnFromLayerName('your_layer_name') in the window "Insert expression" in the label configuration of your layout

See below GIF to illustrate

get attribute column name from QGIS renderer

PS: dirty Python code as I do not try to catch any error here

  • Thank you for the code and gif! It worked like a charm.
    – Peter
    Mar 11, 2021 at 19:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.