Results 1 to 4 of 4

Thread: Qlabel and images

  1. #1
    Join Date
    Feb 2012
    Posts
    33
    Qt products
    Qt4

    Default Qlabel and images

    I need to display jpeg images, and I thought about using a QLabel.

    While I designed the label in the form, I loaded the pixmap property with a jpeg file, and the image is displayed immediately in the form in design phase.
    But when I start the application, the label is blank and I don't see the jpeg image.

    I added a button and when I click on the button reloading the file with these instructions:

    ui->label->setPixmap(QPixmap("presentation.jpg"));
    ui->label->show();

    The file "presentation.jpg" is present in the source directory and also in subfolders "Debug" and "Release".

    Unfortunately I don't see the jpg image on my label.

    Help, please..........

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qlabel and images

    You are using a path relative to the current working directory. When you launch the application the current working directory is not set to the directory containing your image.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Feb 2012
    Posts
    33
    Qt products
    Qt4

    Default Re: Qlabel and images

    Hi,
    I am working in Windows, and I tryied with absolute path:

    ui->label->setPixmap(QPixmap("c:\presentation.jpg"));
    ui->label->show();

    NO DIFFERENCE!!! My Qlabel is empty!!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qlabel and images

    Escape the backslash (or use a forward slash).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 20th January 2011, 10:26
  2. To draw images in QLabel
    By augusbas in forum Qt Programming
    Replies: 5
    Last Post: 11th October 2010, 06:27
  3. Replies: 1
    Last Post: 29th September 2009, 19:44
  4. Replies: 4
    Last Post: 27th July 2009, 15:45
  5. Images in QLabel
    By qball2k5 in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2006, 21:28

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.