Results 1 to 2 of 2

Thread: Adding image to QLabel using QPixmap

  1. #1
    Join Date
    Dec 2014
    Posts
    6
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Adding image to QLabel using QPixmap

    Hello,

    I'm trying to add a label as an image. So I've created a resource under Qt and added in the images, but when I try to run the code it only adds in the image if I give it the extact path and not the short version.

    For example:

    This works
    Qt Code:
    1. void MainWindow::TestIOinputs()
    2. {
    3. QPixmap stat_GO ("C:/Qt/MyProject/images/stat_noGO.png");
    4. ui->label_3->setPixmap(stat_GO);
    5. }
    To copy to clipboard, switch view to plain text mode 

    This doesn't work
    Qt Code:
    1. void MainWindow::TestIOinputs()
    2. {
    3. QPixmap stat_GO (":/images/stat_noGO.png");
    4. ui->label_3->setPixmap(stat_GO);
    5. }
    To copy to clipboard, switch view to plain text mode 

    The resource file is called images and I have added the images there. I can also see that the .pro file has the resources.qrc added in. Any ideas?

  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: Adding image to QLabel using QPixmap

    Make sure the prefix is the same as you set it in the resource file. If you are using Qt Creator you can right click the image file in the list of files and copy its path to clipboard.
    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. Pan/Move QPixmap in QLabel
    By ashtray4241 in forum Qt Programming
    Replies: 5
    Last Post: 14th August 2014, 08:50
  2. geting QLabel text ontop of other QLabel displaying image
    By krystosan in forum Qt Programming
    Replies: 1
    Last Post: 15th December 2013, 17:35
  3. Replies: 3
    Last Post: 10th April 2011, 15:55
  4. QLabel, QPixmap and ScaledContents
    By mhbeyle in forum Qt Programming
    Replies: 3
    Last Post: 28th November 2009, 09:11
  5. Replies: 6
    Last Post: 21st September 2009, 10:55

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.