Image not showing in QLabel
-
-
I don't get it. I have the image as it should be:
Yet when I run it, I get this:
I have it in a folder inside the project. But it doesn't show at showtime.
This is Qt6 6 using CMake. Any insight on this will be appreciated.
Thank you.
@Driftwood Are you using any qresource or are you using the absolute path of the image?
-
@Driftwood Are you using any qresource or are you using the absolute path of the image?
@eyllanesc - I have a .qrc folder for toolbar icons. Should I put the image in there? No, I'm not using an absolute path.
-
@eyllanesc - I have a .qrc folder for toolbar icons. Should I put the image in there? No, I'm not using an absolute path.
@Driftwood If you don't use absolute paths then they will be relative to the executable, so you have the following options:
- you use absolute paths OR
- You locate the resource (the image) relative to the executable that is in the build folder OR
- You use qresource.
-
@Driftwood If you don't use absolute paths then they will be relative to the executable, so you have the following options:
- you use absolute paths OR
- You locate the resource (the image) relative to the executable that is in the build folder OR
- You use qresource.
I've tried both 2 and 3 of your suggestions. The image in the first pic of my initial post is from an /image folder inside the Project folder. Looks fine in Creator. But when I run it, the image vanishes as seen in the 2nd pic.
I'm setting the image path through Creator:
Everything looks great...until I run it.
Why is Qt losing the image? What more needs to be done?
-
I've tried both 2 and 3 of your suggestions. The image in the first pic of my initial post is from an /image folder inside the Project folder. Looks fine in Creator. But when I run it, the image vanishes as seen in the 2nd pic.
I'm setting the image path through Creator:
Everything looks great...until I run it.
Why is Qt losing the image? What more needs to be done?
Hello
For your case, there must be something wrong with image directory
If you are using.qrc
then you can just right click on the name ( picture that you want to insert ) and selectcopy path
or something like that then paste that in the url location (IN QT file revealer at left side(default) )Another way
Click on the down arrow
and select
Choose from resources
Then select resourcefor absolute image
just do the same click Choose from file
and select the fileAnother way of achieving same thing since you are using UI for designing , you can simply use
stylesheet
#yourLabelName{ border-image: url("url of the image here"); }
-
Hello
For your case, there must be something wrong with image directory
If you are using.qrc
then you can just right click on the name ( picture that you want to insert ) and selectcopy path
or something like that then paste that in the url location (IN QT file revealer at left side(default) )Another way
Click on the down arrow
and select
Choose from resources
Then select resourcefor absolute image
just do the same click Choose from file
and select the fileAnother way of achieving same thing since you are using UI for designing , you can simply use
stylesheet
#yourLabelName{ border-image: url("url of the image here"); }
I appreciate your explanation. I have it going now.