I am building a QGIS plugin that can request point features from a WFS, based on criteria defined in the plugins dialog.

Once the results are in, I want to display them with different symbols, based on a field called 'appropriate_symbol'. If a result point-feature has the field value 'fox', it gets a custom made icon of a fox, if the result has a field value 'elephant', it gets a custom made elephant-icon. And so on.

I know that QGIS comes with many svg symbols pre-installed. But I want to use customized symbols and ideally they should be shipped and installed together with the plugin. Is that possible? Can I execute a python command within the plugins __init__ that checks the QGIS installation for the location of svg symbols and adds my own symbols if they are not present already (how would that be implemented)? Or is there are more elegant way?

It is fine if the symbols are available to the user when the plugin is not activated. And it is a rather small user base that would install the plugin from a private repository. But it is important that their custom symbols are implemented, which I why I am looking for an elegant way to deliver them together with the plugin.

1 Answer 1


Of course you can. This is your default path where QGIS keeps svg files (MS Windows):


And you have a lot of possibilities to copy them. For example in your plugin directory put a new folder svg with your files:

+-- _help
+-- _svg
|   +-- file1.svg
|   +-- file2.svg
+-- __init__.py

Then in your plugins __init__() you can copy files to the QGS svg directory, check if they exist or whatever you want.

Copy is simple:

import shutil
shutil.copy2(source_file, destination)

So in plugin you can retrieve each file:

path = os.path.dirname(os.path.abspath(__file__)) + /svg/ # path to svg directory in your plugin
svgs = os.listdir(path) # array with svg filenames

And now you can iterate over this array and copy each file:

for i in svgs:
    shutil.copy(path + i, 'C:/PROGRA~1/QGIS2~1.16/apps/qgis/svg')

If you want you can chceck the condition like If already exists there.

You need to be aware that it won't work on GNU/Linux or MacOS, you need to write config for each system (only change destination path).

And I'm not sure what about user permissions (you want to modify system files) but for sure there is a way to allow this operation.

  • Thanks a lot. I know the users will be working in windows, and hopefuly wont have to ring up their IT department in order to grant them the permission to copy some svgs into the system files. Otherwise I might have to look into a way to make the SVGs be loaded from the plugins directory.
    – Achu Mani
    Mar 16, 2017 at 10:07

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.