编译时jpeg的PyQT4问题

时间:2010-02-05 10:05:26

标签: pyqt4

在PyQT4程序中,我有一个QLabel显示带有以下代码的图像:

初始代码中的

Image=QImage(som_path_from_a_fileDialog)
调整大小方法中的

pixmap = QPixmap.fromImage(Image)
pixmap = pixmap.scaled(self.display.size())
self.display.setPixmap(pixmap)

当我用python执行我的脚本时,它工作正常,我可以显示.bmp和JPEG文件。 如果我使用py2exe编译它,我只能显示.bmp文件。 JPEG文件显示将失败,并显示:

QPainter::begin: Paint device returned engine == 0, type: 3
QPainter::end: Painter not active, aborted
QPixmap::scaled: Pixmap is a null pixmap

编辑: 它是this question

的副本

1 个答案:

答案 0 :(得分:3)

支持最新版PyQt4中的许多图像格式,可通过插件获得。这些插件可以在C:\PythonXY\Lib\site-packages\PyQt4\plugins\imageformats目录中找到。您应该将imageformats目录复制到包含exe的目录中。请注意,您需要在pyapp.exe上放置imageformats目录。或者你应该把你的pyapp.exe所在的目录放在同一个qt.conf中,在那里你可以指定图像插件的路径,例如。

[Paths]
Plugins = Library\plugins

以下是我构建我的exe时复制sqlite插件的代码示例(它不是用于图像,但是你会得到这个想法):

from distutils.core import setup
import py2exe
import os, sys
import PyQt4

setup(options = {"py2exe": {"includes": ["sip"]}},
     data_files=[('sqldrivers', [os.path.join(os.path.dirname(PyQt4.__file__), 
                                              'plugins', 
                                              'sqldrivers', 
                                              'qsqlite4.dll')])],
     windows = ["myapp.py"],
     )