问题
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!
回答1:
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)
来源:https://stackoverflow.com/questions/9933358/pyside-svg-image-formats-not-found