Based on Load .qlr with loadNamedStyle I was able to add a QLR to a python tool via PyQGIS -however, it appears broken...

            elif ftype=='qlr':
                    print ('Loading QLR layer')
                    print("QLR %s called and loading into group %s" % (filePath, fname))
                    print('adding group')
                    print ('Error loading QLR')

fname is the name of the group and file, filepath is the path/file.qlr

The QLR is loading a shp that's in the same folder.

It looks like

 <!DOCTYPE qgis-layer-definition>
  <layer-tree-group checked="Qt::Checked" name="" expanded="1">
    <layer-tree-layer id="events_6d4a5418_1dce_4ba0_201903071250415994831" checked="Qt::Checked" name="events" source="./events.shp" providerKey="ogr" expanded="1">
    <maplayer autoRefreshEnabled="0" labelsEnabled="1" refreshOnNotifyMessage="" maxScale="0" minScale="1e+08" hasScaleBasedVisibilityFlag="0" readOnly="0" styleCategories="AllStyleCategories" autoRefreshTime="0" type="vector" simplifyDrawingTol="1" refreshOnNotifyEnabled="0" simplifyDrawingHints="0" simplifyAlgorithm="0" simplifyLocal="1" simplifyMaxScale="1" geometry="Point">

and it comes out like enter image description here


It works fine if I load it in the QGIS python console using the same commands... enter image description here

Note screen grabs are of a complex and simple QLR I tried but both end up the same...

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.