7

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.

  • 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. – James Greener May 10 '18 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 '18 at 15:50
6

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()
  • Thank you @xunilk. Do you know if I can 'review' or open this *.qml file in console? – W. Tom Jul 15 '16 at 8:41
  • 1
    Yes, you can. It is a markup language xml type. – xunilk Jul 15 '16 at 8:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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