7

I am using PyDev plugin for Eclipse with Qt integration. I have PySide installed and I am having trouble with SVG image formats. I know when I run my application the formats located in C:\Python27\Lib\site-packages\PySide\plugins\imageformats are found. All but the SVG format. I can remove the qico4.dll and it no longer finds them and put it back in and it finds them again.

I am using this line in my code: plugs = QtGui.QImageReader.supportedImageFormats()

It finds all of the formats except the SVG format from the qsvg4.dll? Why would this be? I have searched and searched and searched and can’t seem to find out why. Should the format show up in the supported image formats? Is there something else I need to do to use SVG images? I can use .ico files fine which require the qico4.dll and is located in the same place which is why I am not understanding what the problem is? Any help is appreciated!

Thomas Wouters
  • 130,178
  • 23
  • 148
  • 122
  • Can you do `from PySide import QtSvg`? – Avaris Mar 29 '12 at 21:14
  • Yes I can do that and use it. It still doesn't show up in supported image formats. I 'm trying to use an SVG image the same way I would an ICO image in a style sheet. The ico works whether I put it in a resource file or just link to it directly. The svg files won't work either way. This is why I'm confused. It seems like the interpreter is looking elsewhere for the qsvg4.dll? Or something else needs to be done to specify it as an image format? :-/ – user1301848 Mar 29 '12 at 22:00
  • I've even set everything up on another computer running vista. The other computer is an XP. Still doing the same thing. Isn't the qsvg4.dll suppose to work like all the other image format dlls? gif, jpeg, etc. are all working fine... – user1301848 Mar 29 '12 at 22:04
  • It is odd. My `PySide` and `PyQt4` finds it just fine (Win7). Are you using the latest version? Maybe there was some bug in `PySide`. – Avaris Mar 30 '12 at 00:41
  • does svg show up in the list QtGui.QImageReader.supportedImageFormats() – user1301848 Mar 30 '12 at 02:10
  • Ok, I installed everything on Windows 7 and still doing the same thing. I installed Python 2.7, Eclipse, MinGw, and PySide. Still not showing the svg as an image format, but does show ico, jpeg, gif, etc. I have these in my Environment variable Path: C:\Python27\Lib\site-packages\PySide;C:\Python27\Lib\site-packages; – user1301848 Mar 30 '12 at 18:24
  • Ok, I installed everything on Windows 7 and still doing the same thing. I installed Python 2.7, Eclipse, MinGw, and PySide. Still not showing the svg as an image format, but does show ico, jpeg, gif, etc. I have these in my Environment variable Path: C:\Python27;C:\Python27\Lib\site-packages; I also have these in my PYTHONPATH: C:\Python27, C:\Python27\DLLs, C:\Python27\lib, C:\Python27\lib\plat-win, C:\Python27\lib\lib-tk, C:\Python27\lib\site-packages. Any thoughts on what might be wrong? – user1301848 Mar 30 '12 at 18:33
  • Heres my qt.conf file. [Paths] Prefix = C:/Python27/Lib/site-packages/PySide Binaries = . Plugins = plugins Translations = translations – user1301848 Mar 30 '12 at 18:34
  • Maybe it's because I'm using the standalone pyside install? Should I download the Qt SDK and use it? Is PySide in the SDK now since it is an add-on? Downloading it now to see... – user1301848 Mar 30 '12 at 19:14
  • I am not sure what's going on. Standalone install should be fine. I use it like that. Maybe you can give `PyQt4` a try? – Avaris Mar 30 '12 at 21:17
  • So, you think I have everything setup right then? There's nothing special I need to do to get svg formats working? If I do this line of code in the Eclipse debugger "plugs = QtGui.QImageReader.supportedImageFormats()" I get 15 formats from bmp to xpm. It does the same thing with PyQt4.. – user1301848 Mar 31 '12 at 19:30
  • AFAIK, there shouldn't be any special setting to use `svg`. And what are those 15 formats? I have 16 with `svg` and `svgz` being two of them. – Avaris Mar 31 '12 at 20:10
  • bmp, gif, ico, jpeg, jpg, mng, pbm, pgm, png, ppm, tga, tif, tiff, xbm, xpm. There's what I have. Here's what I installed: eclipse-SDK-3.7.2-win32, mingw-get-inst-20111118.exe, PySide-1.1.0qt474.win32-py2.7.exe, python-2.7.2.msi, qt-eclipse-integration-win32-1.6.1.exe, PyDev 2.4.0.2012020116... Maybe something's wrong with one of these versions? – user1301848 Mar 31 '12 at 20:42
  • I've decided just to use QtCreator and C++. This Python binding and stuff just seems to be too much of a hassle and something is buggy about it. SVG works great with C++ I think there's a bug somewhere in one of the installations I used, so maybe I'll try again at a later date. If anyone has any suggestions I will gladly try them. Thanks Avaris for your time and help. – user1301848 Apr 03 '12 at 18:32

1 Answers1

12

In order to use SVG images, you need to import QtSvg and QtXml and also ensure that the plugin directory is imported properly.

The following code does that successfully for me:

import os
import PySide
from PySide import QtSvg, QtXml
# You need to have created your QApplication already...
qApp = QApplication.instance()
for plugins_dir in [os.path.join(p, "plugins") for p in PySide.__path__]:
    qApp.addLibraryPath(plugins_dir)
David Fraser
  • 6,475
  • 1
  • 40
  • 56