Friday 15 March 2019

pyqgis - Go through items in a composer legend (QGIS 2.6)


I'm trying to develop a plugin in QGIS 2.6, which opens a composer, add a map and a legend, and (among other things) adjusts the legend.


Is there a way to go through items in a composer legend with PyQgis? What I'd want in the end is to change the item name, depending on the type of item (group, raster ...).


Here is my code:


for legend in self.composition.items():

if isinstance(i,QgsComposerLegend):
legend.setAutoUpdateModel(True)
legend.setLegendFilterByMapEnabled(True)
for item in legend.items():
if item.itemtype() == QgsComposerLegendItem.GroupItem:
groupItem.setUserText() = 'another text'

Qgis answers that QgsComposerLegend has not attribute called "items" (which I expected). I looked for a property to iterate on legend items, and I have not found it in the API documentation nor in web searches.




No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...