<div dir="ltr"><div>Hey,</div><br>QLR files are not style files  they can't be loaded like that.   Unfortunately the API for loading a QLR is broken in 2.8.1 but will be fixed in 2.8.2, however the logic isn't very complex and you can translate it to Python from C++.  The source is here <a href="https://github.com/qgis/QGIS/blob/master/src/core/qgslayerdefinition.cpp#L36">https://github.com/qgis/QGIS/blob/master/src/core/qgslayerdefinition.cpp#L36</a>.<div><br></div><div>If you don't need to support loading groups from the QLR you can use this:<br><br>QList<QgsMapLayer*> layers = QgsMapLayer::fromLayerDefinition( doc );</div><div>QgsMapLayerRegistry::instance()->addMapLayers( layers, True);</div><div><br></div><div>- Nathan</div><div><br></div></div><br><div class="gmail_quote">On Thu, 16 Apr 2015 at 16:51 Geo DrinX <<a href="mailto:geodrinx@gmail.com">geodrinx@gmail.com</a>> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>Very strange   :(<br><br></div>I inserted also the    triggerRepaint()   but nothing changes.<br><div><div><br></div><div>This is my sourcecode:<br><br><a href="https://github.com/geodrinx/smartroadsense/blob/master/smartroadsense.py" target="_blank">https://github.com/geodrinx/smartroadsense/blob/master/smartroadsense.py</a><br><br><br></div><div>If I drag and drop in  QGIS  my  "srs_data.qlr"   file, it works.<br></div><div><br>Instead, from python code, the style is not applied.<br><br></div><div><span lang="en"><span>Could</span> <span>be because</span> <span>my</span> <span>data file is</span> <span>a</span> <span>CSV</span><span> ?</span></span></div><div><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2015-04-15 18:39 GMT+02:00 Gary Sherman <span dir="ltr"><<a href="mailto:gsherman@geoapt.com" target="_blank">gsherman@geoapt.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On 4/15/15 2:24 AM, Geo DrinX wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
<br>
there is a way to load a QLR file with  pyQGIS ?<br>
<br>
I tried using      vlayer.loadNamedStyle(<u></u>qlrFileName)    but it seems<br>
not to work.<br>
<br>
<br>
What is the correct way ?<br>
<br>
</blockquote></div></div>
That is the correct way. Have you done the following after applying the style?:<br>
<br>
vlayer.triggerRepaint()<br>
<br>
You can test the result of applying the style using:<br>
<br>
result = vlayer.loadNamedStyle(<u></u>qlrFileName)<br>
<br>
If result if False, the style was not loaded/applied.<br>
<br>
-gary<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Thank you<br>
<br>
Roberto<br>
<br>
<br>
______________________________<u></u>_________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/qgis-<u></u>developer</a><br>
<br>
</blockquote>
<br>
-- <br>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<br>
Gary Sherman<br>
<br>
Founder, QGIS Project<br>
Consulting: <a href="http://geoapt.com" target="_blank">geoapt.com</a><br>
Publishing: <a href="http://locatepress.com" target="_blank">locatepress.com</a><br>
<br>
We work virtually anywhere<br>
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=<br>
______________________________<u></u>_________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/<u></u>mailman/listinfo/qgis-<u></u>developer</a><br>
</blockquote></div><br></div>
_______________________________________________<br>
Qgis-developer mailing list<br>
<a href="mailto:Qgis-developer@lists.osgeo.org" target="_blank">Qgis-developer@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a></blockquote></div>