Results 1 to 15 of 15

Thread: Insert picture in a form using label

  1. #1
    Join Date
    Apr 2009
    Posts
    12
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Insert picture in a form using label

    Hey guys

    I want to insert a picture in an label

    I used the following code

    Qt Code:
    1. label->setPixmap(QPixmap("download.jpg"));
    To copy to clipboard, switch view to plain text mode 

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

    Could you tell me how to fix this.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Insert picture in a form using label

    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.

  3. The following user says thank you to Lykurg for this useful post:

    cwnelatury (3rd June 2009)

  4. #3
    Join Date
    Jan 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    that is absolutely not the problem.
    I used pixmap before and the picture was there (not animated).

  5. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Insert picture in a form using label

    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.

  6. #5
    Join Date
    Oct 2009
    Posts
    151
    Thanks
    6
    Thanked 13 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    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?

  7. #6
    Join Date
    Jan 2010
    Posts
    5
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    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/2720...Label-or-other

  8. #7
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: Insert picture in a form using label

    I'm having the same problem.

    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

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Insert picture in a form using label

    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.

  10. The following user says thank you to Lykurg for this useful post:

    grantbj74 (17th March 2010)

  11. #9
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    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.

  12. #10
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Insert picture in a form using label

    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/deploym...tml#qt-plugins for more informations.

  13. #11
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    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).

  14. #12
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    what if you place imageformats directory in AppDirectory and not plugins ?
    Does it works ?

  15. #13
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    No, I couldn't get that to work.

  16. #14
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Insert picture in a form using label

    debug where your application is looking for libraries. And then place the dll there.

  17. #15
    Join Date
    Aug 2009
    Location
    Brisbane, Australia
    Posts
    75
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert picture in a form using label

    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.

Similar Threads

  1. [Qt4.1] How to insert an image inside a Form?
    By Gonzalez in forum Qt Tools
    Replies: 5
    Last Post: 23rd September 2008, 12:20
  2. How to insert an image in background of a Form?
    By awanish_jmi in forum Qt Tools
    Replies: 2
    Last Post: 8th August 2008, 11:52

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.