PDA

View Full Version : Insert picture in a form using label



cwnelatury
18th April 2009, 19:45
Hey guys

I want to insert a picture in an label

I used the following code




label->setPixmap(QPixmap("download.jpg"));



however when I run the program, everything displays except the picture.

Could you tell me how to fix this.

Lykurg
18th April 2009, 20:12
I guess that the picture isn't found. Please use a full path name to the picture and make sure that you (your program) has read access to the file. You can also have a look the resource system of qt for shipping images alongside your app.

AngiSad
13th January 2010, 12:48
that is absolutely not the problem.
I used pixmap before and the picture was there (not animated).

yogeshgokul
13th January 2010, 13:21
If you are sure that image is in same folder with executable, then it could be 2-3 problems.
1. Image is corrupt.
2. Your application is not finding the image formats plugins.
3. May be some problem with your GUI.

JD2000
13th January 2010, 13:26
As with Lykurg and Yogeshgokul, I believe that cwnelatury's code should work if QT can find a valid Jpg.
It is probably creating a null pixmap and hence has has nothing to display.

AngiSad - how about some code to examine?

AngiSad
13th January 2010, 14:55
I am sorry I did a mistake and posted in the wrong thread.
My problem is how to insert an animated picture (GIF).
here is my thread:
http://www.qtcentre.org/threads/27203-How-to-insert-an-animated-picture-(GIF)-in-a-QLabel-or-other

grantbj74
16th March 2010, 05:45
I'm having the same problem. :confused:

In QT Designer I have text in the QLabel, After I attempt to load the image the text disappears from the QLabel, but no image. I don't really want any text anyway.

1) How do you setup the plugin (I'm trying to show a jpg).
2) Is it ok to load the image from a qrc resource file.

Thanks
Brendan

Lykurg
16th March 2010, 09:23
Before going to deal with the plugin, make an example with an png file to see if your code works well. If so we see on...

To 2) Yes that is ok.

grantbj74
17th March 2010, 02:55
Thanks

I got the png image working, I had to make sure the image was in the same folder as the executable.

After lots of toil and trouble I got the png image working with the resource file. I had trouble because I was using a make file instead of a project file. Probably not worth posting the results because its a bit of a mess with make files all over the shop.

Now I just need to get the jpeg image working. Probably easier to just convert to png, but would be interesting anyway.

Lykurg
17th March 2010, 06:22
Fine. You have to deliver the qipeg4.dll (or qjpegd4.dll if you build your application in debug mode) with your application. This file has to be in a folder relative to your executable named: imageformats. (Since I am not often on widnows, it also can be plugins/imageformats). Then your jpeg should be displayed.

See http://doc.trolltech.com/4.6/deployment-windows.html#qt-plugins for more informations.

grantbj74
18th March 2010, 00:12
Thanks,

Yeah I copied both dll's to the plugins\imageformats folder where the executable is. And no luck.

The collidingmice demo also had the same problem no cheese.jpg displayed. Maybe it doesn't like Windows XP like everyone else :)

I would have thought you would need to define it somewhere like sql (QT += sql).

aamer4yu
18th March 2010, 04:26
what if you place imageformats directory in AppDirectory and not plugins ?
Does it works ?

grantbj74
18th March 2010, 04:43
No, I couldn't get that to work. :confused:

Lykurg
18th March 2010, 07:00
debug where your application is looking for libraries. And then place the dll there.

grantbj74
18th March 2010, 23:43
Thanks for your help.

Don't worry about it i'll just use a PNG image.

I tried putting the dll into the same path as exe, and a library path (wasn't sure how to debug the library path info).

I'll just put this into the too hard basket. At least with PNG's, I don't need to supply the extra dll. :)