2

I've been building up QgsLayerTree object with a directory structure that reflects the desired legend.

Specifically, I'd like the Group(s) to be titles and their contained layers to legend items. However, only blank spaces appear where the Group's title would be. You can see here:

example

The code I'm using is as follows:

    ### LEGEND
    composerLegend = QgsComposerLegend(c)
    composerLegend.setColumnCount(3)
    composerLegend.setEqualColumnWidth(True)
    composerLegend.setBackgroundEnabled(True)
    composerLegend.setBackgroundColor(QColor('white'))
    composerLegend.setFrameEnabled(True)
    composerLegend.setFrameOutlineColor(QColor('red'))
    composerLegend.setFrameOutlineWidth(1)
    composerLegend.setTitle('Land Uses')
    composerLegend.setStyleFont(QgsComposerLegendStyle.Title, QFont("Ubuntu", 60))
    composerLegend.setStyleFont(QgsComposerLegendStyle.Group, QFont("Ubuntu", 50))
    composerLegend.setStyleFont(QgsComposerLegendStyle.Subgroup, QFont("Ubuntu", 30))
    composerLegend.setStyleFont(QgsComposerLegendStyle.SymbolLabel, QFont("Ubuntu", 15))
    composerLegend.setSymbolHeight(5)
    composerLegend.setSymbolWidth(10)
    output_group = self.findGroup('Land Uses')
    composerLegend.modelV2().setRootGroup(output_group)
    #composerLegend.synchronizeWithModel()
    composerLegend.adjustBoxSize() # this is the last operation before adding
    c.addItem(composerLegend)
    self.setLegendPosition(composerLegend, 10, 10)

Your Answer

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

Browse other questions tagged or ask your own question.