I am trying to change the SVG path with Python but I couldn't find any document which explains how to do this. This is what I want to do I Added SVG symbols to my plugin in a specific folder. When the plugin initiates I want to check SVG paths in system/ option. if the path does not exist then I want to add it.

enter image description here

I tried the following code in python console but It does Nothing

 QSettings().setValue(u'/qgis/system/Qgis/system/svg_paths', u'C:\1234m')

it gives no error but It does nothing.


Tested in QGIS 3.2 python console under Ubuntu 18.04 :

To find the settings you need, you can use

settings = QSettings().allKeys()

This will create a list of all available Settings (it can help to find the settings you need)

for setting in settings:
    if 'svg' in setting:

will print 'svg/searchPathsForSVG'

Then you can use this strings to play with the setting. The searchPathsForSVG is stored as a list of paths so you first need to retrieve the current list (eventually loop on it to check what you want) and if everything is good append your new path.

my_new_path = '/toto/titi/tata'
svg_paths = QSettings().value('svg/searchPathsForSVG')
if my_new_path in svg_paths:
    QSettings().setValue('svg/searchPathsForSVG', svg_paths)

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.