PyQGIS – Loading Style (*.qml File) to Layer

coding-stylepyqgisqmlstyle

Is there any way to load a *.qml file to layer and set a style to it in python (pyqgis)?

Can I 'get into' this file in console? I want to review it.

Best Answer

I have my qml styles in a fix path (c:/pyqgis_data/Styles/). So, to load arrows_red_orange.qml (exclusively for point layers), next lines at the Python Console of QGIS work:

>>>layer = iface.activeLayer()
>>>if layer.geometryType() == QGis.Point:
>>>...layer.loadNamedStyle('c:/pyqgis_data/Styles/arrows_red_orange.qml')
>>>layer.triggerRepaint()