Image not loading using Designer and Pixmap
-
Hey, I am using pyqt5 and tried to add a logo to the gui that i am currently making, with the help of rich text as well as pixmap in the python for qt designer, and it shows well on the designer itself but when I run the python script the image is not loading, and i dont understand why exactly, can someone help?
-
Hi,
How is that image passed ?
A path to a file in your system ?
Through Qt's resource system ? -
@SGaist this is what I did:
I used the label display widget and then changed the rich text of the label in which I add a resource file leading to the logo that i want to add and then added that resource file on the rich text.
Additionally, I changed the pixmap of the label and selected the same resource file image that I had created for the rich text alteration.
Did I do something wrong? I can see it load on the designer however it is not showing up when I run the application through my python script. -
@artiekastle
In a word: I imagine somewhere in what you did you specified a path to the physical image file? If that is a relative path then it is relative to "the current directory". And that may not be the same when in the Designer/Creator versus what it is when you run your Python script (you don't say where/how you do that).Try to see if you can find such a path (
.ui
file or generated.py
file). Either make it absolute, so it works independently of the current dircetory, or consider moving over to Qt resource files for it, which "embed" the actual image in the executable (not sure how this works for Python, but there will be documentation/links for this out there). t any rate look to see if that seems to be the issue. -
@JonB So I added the image as a static path to like the current directory where both the main.py file which has the code and the other .ui.py files also are located. Since all the files including the logo png file are located in one location. I added a resource file in the designer redirecting to where the logo file is located. But the logo is still not loading.
-
@artiekastle if you are using a resource file you have to use rcc to build a python file out of it in order to use it in your application.
-
@artiekastle sure: follow the documentation :-)