PDA

View Full Version : JPG not working when calling setPixmap() on QLabel



Deusdies
24th May 2012, 15:40
I am trying to have a QLabel() display a pixmap JPG image from a file (which can't be in a resource file since it is downloaded from the web), but I am having problems loading it. The code is fairly simple:



label = QLabel()
label.setPixmap(QPixmap("image.jpg"))

It works with PNG files, but it doesn't work with JPG files. I have Googled quite a bit and found that I needed to place the "imageformats" folder in the same folder where my script is located. However, even after doing this (and yes, qjpeg4.dll and others are there), it still doesn't work. I've also tried doing


path = r"C:\Users\Deusdies\Documents\Work\myapp\imageformat s"
app.addLibraryPath(path)

but that didn't help either.

Again, it loads PNGs just fine, but it won't load JPGs. I've also noticed even before that it won't load ICO either, but I thought of it as an unrelated issue - however it doesn't seem that way now.

It is worth noting that the application is not converted to an .exe at this point - it is ran through python.exe interpreter via PowerShell.

My development environment is Windows 7 x64, PySide 1.1.0

How can I solve this problem?

ChrisW67
25th May 2012, 00:29
Sounds like the binaries in the imageformats folder do not match the binaries of the Qt libraries you are using, i.e. debug vs. release, built with the same compiler version etc. Where did you get the imageformats folder from?

Deusdies
25th May 2012, 00:31
From the PySide folder in the Python27 folder on my machine.

But anyway, I solved the problem. I removed the "imageformats" part from the path above, then added the path to the library. It works now.