17

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.

2
  • Thank you @xunilk! This worked for me once I put these lines of code into the Python Console's Script editor, and ran the script. I am new to using Python in QGIS so more experienced users would probably not need to know that. May 10, 2018 at 15:25
  • Please don't add "thank you" as an answer. Once you have sufficient reputation, you will be able to vote up questions and answers that you found helpful. - From Review
    – aldo_tapia
    May 10, 2018 at 15:50

1 Answer 1

19

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()
3
  • Thank you @xunilk. Do you know if I can 'review' or open this *.qml file in console?
    – W. Tom
    Jul 15, 2016 at 8:41
  • 1
    Yes, you can. It is a markup language xml type.
    – xunilk
    Jul 15, 2016 at 8:53
  • 2
    You should use QgsWkbTypes.PointGeometry instead of QGis.Point in QGIS 3.x Dec 18, 2019 at 11:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.