Results 1 to 6 of 6

Thread: Images in QLabel

  1. #1
    Join Date
    Mar 2006
    Posts
    26
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Images in QLabel

    Hey!

    I'm new to QT4...I've created my UI in the Designer. In my UI I have 5 lables that I would like to put images in. So in the pixmap property for each label...I put in the image I want. However when I compile and run the application, the images don't show up.

    I can't figure out what I'm doing wrong. I'm assuming that the generated code is accurate. I don't have any code yet....except a standard main.cpp...copied from the tutorials.

    Here's what is generated for each label

    Qt Code:
    1. label = new QLabel(tabProcess);
    2. label->setObjectName(QString::fromUtf8("label"));
    3. label->setGeometry(QRect(140, 100, 100, 100));
    4. label->setPixmap(QPixmap(QString::fromUtf8("stop_image_70.png")));
    5. label->setAlignment(Qt::AlignCenter);
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Images in QLabel

    Are the images located in the working dir (where you are running your app from)?

    Add a check for pixmap loading succeeding:
    Qt Code:
    1. QPixmap pixmap(QString::fromUtf8("stop_image_70.png"));
    2. qtDebug() << pixmap.isNull();
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Mar 2006
    Posts
    26
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Images in QLabel

    The images are located where the executable is.

    And QTDebug doesn't work...I get `qtDebug' undeclared (first use this function)
    Last edited by qball2k5; 6th March 2006 at 20:30.

  4. #4
    Join Date
    Jan 2006
    Location
    N.B. Canada
    Posts
    47
    Thanked 8 Times in 7 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Images in QLabel

    Also, how are you running your application? If you run it from the file manager (ie. Konqueror), the working directory will probably be different than if you run it from command line. If you run it from a file manager, it is likely that the app's working directoy will be your home directory. Then the pixmap wont be found, and you'll have a null pixmap.

    Use qDebug not qtDebug, I think that was a typo.

    Bojan
    The march of progress:
    C:
    printf("%10.2f", x);
    C++:
    cout << setw(10) << setprecision(2) << showpoint << x;
    Java:
    java.text.NumberFormat formatter = java.text.NumberFormat.getNumberInstance();
    formatter.setMinimumFractionDigits(2);
    formatter.setMaximumFractionDigits(2);
    String s = formatter.format(x);
    for (int i = s.length(); i < 10; i++) System.out.print(' ');
    System.out.print(s);

  5. The following user says thank you to Bojan for this useful post:

    qball2k5 (6th March 2006)

  6. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Images in QLabel

    Quote Originally Posted by qball2k5
    And QTDebug doesn't work...I get `qtDebug' undeclared (first use this function)
    Qt Code:
    1. #include <QtDebug>
    To copy to clipboard, switch view to plain text mode 

  7. The following user says thank you to jpn for this useful post:

    qball2k5 (6th March 2006)

  8. #6
    Join Date
    Mar 2006
    Posts
    26
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Images in QLabel

    Thanks guys!

    I was able to figure it out....I had been running from Konquerer not from command line as you noted...I will run from command line from now on.

    Thanks to you both/all...I don't remember how many people replied.

Similar Threads

  1. Trouble with QLabel
    By dany_MB in forum Newbie
    Replies: 3
    Last Post: 14th August 2009, 08:21
  2. Load Images in a dir into a QScrollArea
    By nmuntz in forum Qt Programming
    Replies: 3
    Last Post: 20th January 2009, 21:03
  3. Replies: 3
    Last Post: 17th July 2008, 07:43
  4. import large number of images
    By sriluyarlagadda in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2008, 10:26
  5. QLabel ScaledContents ignored by style sheet?
    By WinchellChung in forum Newbie
    Replies: 3
    Last Post: 27th February 2008, 14:50

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.