0

I want to display the 'name' or 'title' of the active layer in View-Decorations-Title, I found in "Automatically create an array of all visible layer names in QGIS" the answer:

array_to_string(
  array_foreach ( 
    @map_layers,
    layer_property(@element,'name')
  )
)

but, it shows all visible layers, and I can't find an expression for the current layer that can use in something like:

layer_property('active_layer???','title')

I'm using QGIS 3.26.3 in LinuxMint 20.2.

1 Answer 1

2

there is no predefined function or expression for that, you will have to write a python function in the Function editor:

enter image description here

with following code

from qgis.core import *
from qgis.gui import *
from qgis.utils import iface

@qgsfunction(group='Custom', referenced_columns=[])
def active_Layer(feature, parent):
    """
    returns the active Layer name.
    """
    s = iface.activeLayer().name()
    return s

then you will a a new expression which returns the active Layers name

enter image description here

1
  • perfect solution, thanks a lot!
    – Javier
    Commented May 25 at 6:13

Your Answer

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

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