QLabel () does not load pixmap if it is a jpg image

I am trying to show QLabel() a pixmap JPG image from a file (which may not be in the resource file, since it is downloaded from the Internet), but I am having problems downloading it. The code is pretty simple:

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

It works with PNG files, but does not work with JPG files. I have quite a bit of Googled, and I found that I need to place the "imageformats" folder in the same folder as my script. However, even after that (and yes, qjpeg4.dll and others are), it still does not work. I also tried to do

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

but that didn't help either.

Again, it loads PNGs just fine, but it doesn't load JPGs . I also noticed that even before that, he would not load the ICO , but I thought of it as an unrelated problem, but now it does not look like that.

It is worth noting that the application does not convert to .exe at this moment - it passes through the python.exe interpreter through PowerShell .

My development environment is Windows 7 x64, PySide 1.1.0

How can I solve this problem?

+6
source share
1 answer

I solved the problem. First, the path should look like this:

 path = r"C:\Users\Deusdies\Documents\Work\myapp" 

(therefore, without the "imageformats" part)

And secondly, I was an idiot. I created an instance of the QDialog () class before doing addLibraryPath()

+5
source

Source: https://habr.com/ru/post/916572/


All Articles