简体   繁体   English

如果它是JPG图像,QLabel()将不会加载像素图

[英]QLabel() won't load a pixmap if it is a JPG image

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. 我正在尝试让QLabel()从文件中显示pixmap JPG图像(由于它是从Web下载的,因此不能在资源文件中),但是我在加载它时遇到问题。 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. 它适用于PNG文件,但它不适用于JPG文件。 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. 我谷歌搜索了很多,发现我需要将"imageformats"文件夹放在我的脚本所在的同一文件夹中。 However, even after doing this (and yes, qjpeg4.dll and others are there), it still doesn't work. 但是,即使这样做(是的, qjpeg4.dll和其他人在那里),它仍然无法正常工作。 I've also tried doing 我也尝试过

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 won't load JPGs . 再次,它加载PNGs就好了,但它不会加载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. 我甚至在此之前也注意到它也不会加载ICO ,但我认为这是一个无关的问题 - 但现在看来并不是这样。

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 . 值得注意的是,此时应用程序未转换为.exe - 它通过PowerShell运行python.exe解释器。

My development environment is Windows 7 x64, PySide 1.1.0 我的开发环境是Windows 7 x64,PySide 1.1.0

How can I solve this problem? 我怎么解决这个问题?

I solved the problem. 我解决了这个问题。 First, path should look like this: 首先,路径应如下所示:

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

(so without the "imageformats" part) (所以没有“imageformats”部分)

And second, I was an idiot. 第二,我是个白痴。 I created an instance of the QDialog() class before doing the addLibraryPath() 我在创建addLibraryPath()之前创建了一个QDialog()类的实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM