2

Relative path for svg symbols in .qml files works as expected if the svg file is in another directory than the .qml file's. Example :

<prop k="name" v="../icons/symbol.svg"/>

However, if the svg file is in the same directory as the .qml file, it doesn't. I tried with this syntax :

<prop k="name" v="symbol.svg"/>

And this one :

<prop k="name" v="./symbol.svg"/>

With no success... Is it a bug or do I miss something ?

1 Answer 1

3

The QML location is irrelevant. Once you have selected the qml file to apply it to a layer in your project, its information is "copied" to the project file - which is likely somewhere else.

SVG paths in the QML file are relative to the path you have declared in QGIS options. You can add a new path pointing to the folder holding the qml + svg if you want.

svg paths

3
  • The context being a plugin, I could indeed add programatically the path to qml and svg files. But I still don't understand why relative paths work in the case of a different directory (which indeed appears in the svg symbol path in the layer's properties dialog).
    – sigeal
    Commented Oct 11, 2017 at 15:44
  • @sigeal Probably because the relative path, from one of the declared svg folder, match the one in your QML. (ex: svg folder = c:\svg\, your file is in c:\icons\, so "../icons" means "start from c:\svg\, go up to c:, go down to c:\icons " and it finds your svg there.)
    – JGH
    Commented Oct 11, 2017 at 15:54
  • I checked that but it is not the case... The other workaround I found so far is to update svg path in the qml file when the plugin is loaded.
    – sigeal
    Commented Oct 11, 2017 at 18:42

Your Answer

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

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