I'm trying to call QgsRendererV2PropertiesDialog from a standalone Qgis python script. It mostly works, except there's some "unknown error" messages related to SVG files when I trigger the dialog:

Cannot open file ':/images/themes/default/sort.svg', because: Unknown error
Cannot open file ':/images/themes/default/sort.svg', because: Unknown error
Cannot open file ':/images/themes/default/symbologyAdd.svg', because: Unknown error
Cannot open file ':/images/themes/default/symbologyAdd.svg', because: Unknown error

and the relevant buttons that should have those icons are blank. The dialog looks fine with no missing buttons when I run Qgis itself.

Here's a test script that fires up a symbology dialog that produces the error for me, and one line after it that also produces the error when trying to load an icon. The missing icons are under the symbology layer list, with functions like new layer, lock colour, move layer up/down etc:

from qgis.core import *
from qgis.gui import *
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *

app = QgsApplication([], True)
app.setPrefixPath("/usr", True)
print QgsApplication.showSettings() 

layer = QgsVectorLayer("point","point","memory")
if not layer.isValid():
    raise ValueError,"Layer not valid"

dialog = QgsRendererV2PropertiesDialog(layer, QgsStyleV2.defaultStyle(), embedded=False)

print QIcon(QgsApplication.iconPath( "symbologyAdd.svg" ) )


Note that the settings printed out by QgsApplication.showSettings() are the same in this script and in Qgis. I'm thinking there's some app initialisation that I've not done. I can't find the resource file that has those icons in it. The icon path is the same in my script, namely: ":/images/themes/default/symbologyAdd.svg".

So, any solution?

1 Answer 1


Martin Dobias suggested on the qgis list that the resources are probably compiled into the QGis executable, and so not available to Python standalone scripts.

Solution is to download the QGis source, create a resource description file, build a python resource file and import that.

Here's subset.qrc for the icons I need:

  <qresource prefix="/images">

Download the QGis source and put this file in the images folder. Run

pyrcc4 subset.qrc >resources.py

and then copy resources.py to somewhere my script can get it. Then in my script I just import resources and all the icons appear.

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.