开发者

PyQT4 issue with jpeg when compiled

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


Support for many image formats in recent versions of PyQt4 available via plugins. These plugins could be found in your C:\PythonXY\Lib\site-packages\PyQt4\plugins\imageformats directory. You should copy imageformats directory to the directory with your exe. Please note, that you need to have imageformats directory right along the your pyapp.exe. Or you should put in the same directory where is your pyapp.exe located special qt.conf where you can specify the path to the image plugins, e.g.

[Paths]
Plugins = Library\plugins

Here is example of the code to copy sqlite plugin (it's not for images, but you will get the idea) when I built my exe:

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"],
     )
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜