I would like to freeze the names of layers in TOC. Is there any way to do this via QGIS config or PyQGIS?

I´m using QGIS Wien.

  • "freeze names" ... u mean forbid any name change ?
    – Snaileater
    May 19, 2015 at 16:39
  • Exactly @snaileater.
    – Sassá
    May 19, 2015 at 16:55

3 Answers 3


You can (sort of) achieve it by modifying the QGIS layer tree model. Write the following code snippet in a QGIS Python console:

treeview = iface.layerTreeView()
model = treeview.layerTreeModel()

model.setFlag(QgsLayerTreeModel.AllowNodeRename, False)

After running the code, renaming layers (and groups) from the layer tree is no longer possible, although it can be done via the Properties dialog or via PyQGIS.

I guess that would be the most you can get.


You can reference/embed the layers from a second file. (by using the "Layer - Embed Layers and groups" menu entry)

Layers that are embedded like that are read-only (so you can't rename them). You can move them around temporarily but those changes don't get saved.

  • 1
    Thanks @Max but not quite that. I need to keep editable layers.
    – Sassá
    May 19, 2015 at 18:46
  • Ok, didn't see that in your question. Hope you find out!
    – Max
    May 19, 2015 at 18:49

I'm not an expert but here's what i would do :

At startup maintain a lookup table containing the layer id and the corresponding name u want to be left unchanged.

Then i would use the layerNameChanged signal with a line of this kind :


You do that for every layer of your project.

then in the slot "watchName" u try a :

def watchName(self):

I didn't write all the necessary code to create the lookup table.


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.