1

With the following code, I did not succeed to get the first group name of the tree.

from qgis.core import *
from qgis.gui import *
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import os
#coding=system


def group_name():
  root = QgsProject.instance().layerTreeRoot()
  print root.name()


group_name()
1

If you just want to get the name of the groups, try this:

for group in iface.legendInterface().groups():
    print group

And the firt group name only:

groups = iface.legendInterface().groups()
groups[0]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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