Results 1 to 4 of 4

Thread: display image in qlabel

  1. #1
    Join Date
    Sep 2008
    Posts
    84
    Thanks
    28
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default display image in qlabel

    i want to display simple image on qlabel.
    My application is on C: while the images to load is on D:\images\img1.jpg
    The label is made in designer .

    I have tried several way to load it but is unsuccessful.
    Someone Please help

    Here is the code i have tried :

    Code 1 :
    Qt Code:
    1. ui.label->setPixmap(QPixmap(D:\images\img1.jpg));
    To copy to clipboard, switch view to plain text mode 

    Code 2:
    Qt Code:
    1. QString img_path ="D:/images/img1.jpg";
    2. ui.label->setPixmap(QPixmap(img_path));
    To copy to clipboard, switch view to plain text mode 

    Please someone help to find the error.

  2. #2
    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: display image in qlabel

    Was your Qt built with jpeg support ?
    You need to add -qt-libjpeg to configure.exe options.

    Otherwise code looks fine. you can try "D:\\images\\img1.jpg"

  3. #3
    Join Date
    Jul 2014
    Posts
    46
    Thanks
    5
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: display image in qlabel

    I also can't get it to work. Tried it with png as well.
    Tried adding the image in resources and then setting style sheet but still not able to view an image.
    Any Help?

  4. #4
    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: display image in qlabel

    Are you running app outside of QtCreator ?

    Does the application directory have imageformats folder ?

Similar Threads

  1. QLabel size, for image display
    By C167 in forum Qt Programming
    Replies: 13
    Last Post: 25th October 2013, 16:09
  2. Replies: 7
    Last Post: 13th August 2008, 18:27
  3. can Qlabel display a series of image one by one ?
    By jirach_gag in forum Qt Tools
    Replies: 3
    Last Post: 11th August 2008, 15:36
  4. Display only PNG image on desktop
    By durbrak in forum Qt Programming
    Replies: 32
    Last Post: 15th March 2008, 21:55
  5. How and when to repaint a widget ?
    By yellowmat in forum Newbie
    Replies: 7
    Last Post: 3rd April 2006, 16:36

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.