2

I have a print layout with a bunch of items, two text labels among them. For the pluging I'm wrting right now I need a list with the two text labels. My initial idea was labels = QgsProject.instance().layoutManager().layouts().QgsLayoutItemLabel().currentText()

However when I try to execute my plugin I get the following python error:

AttributeError: 'list' object has no attribute 'QgsLayoutItemLabel'

Any ideas how to get a list with the text labels?

1 Answer 1

2

Assuming you have only one print layout active, you could use the following to get all labels and the text they contain:

labels = QgsProject.instance().layoutManager().layouts()[0].items()
for x in labels:
    if isinstance(x, QgsLayoutItemLabel):
        print(x)
        #To print the text inside the labels
        print(x.text())

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.