[Qgis-user] applying qml to vector layer with pyqgis

Reginald Reginald.Carlier at ingelmunster.be
Fri Mar 1 00:23:40 PST 2019


Hello list,

I have a whole series of shapefiles and qml files residing in the same
directory.
The shapefiles and the qmlfiles have according names: eg.
Adp36007.shp --> Adp36007.qml
I have read somewhere that those qml files would be applied automaticaly
when I load the shapefiles in the map. That doesn't happen.
So I wrote a quick script:

from qgis.PyQt.QtCore import *
from qgis.PyQt.QtGui import *
from qgis.PyQt.QtWidgets import *
from qgis.utils import iface
from qgis.core import *

layers = [layer for layer in QgsProject.instance().mapLayers().values()]
dirname = "F:/GRB/Recent/"
for lay in layers:
    qmlname = dirname + lay.name() + ".qml"
    lay.loadNamedStyle(qmlname)
    print("processed " + qmlname)
    lay.triggerRepaint()
print("done")

But that doesn't work. Applying the qml via the GUI works so there is
nothing wrong with the qml files.
Has anything changed in QGIS 3.4 with loadNamedStyle?

Regards,



--
Sent from: http://osgeo-org.1560.x6.nabble.com/QGIS-User-f4125267.html


More information about the Qgis-user mailing list