Results 1 to 5 of 5

Thread: QLabel does not show image

  1. #1
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default QLabel does not show image

    Hi guys,

    Simple case, just cannot figure out what I'm doing wrong. I'm using Qt Creator to create simple application. At the first phase, I only want it to show a image in QLabel.

    This is what I have done:

    1. Added the image to resource file.
    2. Added a QLabel to the window.
    3. From the property menu of the QLabel, I have added the image using QLabel->Pixmap option. As a result the image is shown in the Qt Creator just fine and it also shows fine when using the preview tool (ctrl+alt+r).
    4. Everything seem to be fine, but when running the app the image is not shown.

    I also tried setting the image to the QLabel in the cpp, but it didn't help either:

    Qt Code:
    1. QPixmap pixmap( ":/pics/test.jpg" );
    2. ui->label_2->setPixmap(pixmap);
    To copy to clipboard, switch view to plain text mode 

    Then also checked the app with Dependency Walker and nothing seems to be missing.

    Any idea what's wrong?

    Cheers!

  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 does not show 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
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QLabel does not show image

    Quote Originally Posted by Mobility View Post
    Hi guys,
    I also tried setting the image to the QLabel in the cpp, but it didn't help either:
    Qt Code:
    1. QLabel *love = new QLabel();
    2. QImage myImage;
    3. myImage.load(":/xxx.png");
    4. QImage image = myImage.scaled(love->width(), love->height(), Qt::IgnoreAspectRatio );
    5. love->setPixmap(QPixmap::fromImage(image));
    6. love->show();
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QLabel does not show image

    Thanks for your quick replies! Problem was after all with the location of the imageformats folder. I have my sql drivers in app/plugins/sqldrivers directory, so I put the imageformats folder also under app/plugins. Correct place is app/. Wonder why Dependency Walker did not notice this... Anyway now it works, thanks again!

  5. #5
    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 does not show image

    sqldrivers and imageformats should be in the same directory. Unless you somehow changed the default Qt behaviour for your application, your app does not search for sql plugins in the correct place. Try renaming this directory to something else and see if your app reports a missing SQL driver.
    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. show the position in qlabel
    By ready in forum Qt Programming
    Replies: 8
    Last Post: 28th March 2011, 07:58
  2. Qt Creator Maybe I'm stupid or QLabel don't show image, at runtime
    By giancarlo.fir in forum Qt Tools
    Replies: 2
    Last Post: 20th March 2011, 08:52
  3. How to show xy coordinate on QLabel widget
    By matteo.cozzaglio in forum Qwt
    Replies: 8
    Last Post: 11th February 2010, 09:26
  4. Replies: 6
    Last Post: 21st September 2009, 10:55
  5. Show Image on a QLabel
    By ^NyAw^ in forum Newbie
    Replies: 11
    Last Post: 15th April 2008, 15:45

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.