0

In a PyQT4 program, I have a QLabel displaying an image with the following code :

in the init code :

Image=QImage(som_path_from_a_fileDialog)

in the resize method :

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

When I execute my script with python, it works fine, and I can display .bmp and JPEG files. If I compile it using py2exe however, I will only be able to display .bmp files. JPEG File display will fail with :

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

EDIT : It is a duplicate of this question

4

1 回答 1

3

支持通过插件提供的最新版本 PyQt4 中的许多图像格式。这些插件可以在您的C:\PythonXY\Lib\site-packages\PyQt4\plugins\imageformats目录中找到。您应该使用 exe 将目录复制imageformats到该目录。请注意,您需要在imageformatspyapp.exe 旁边有目录。或者您应该将 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"],
     )
于 2010-02-05T11:28:20.697 回答