Results 1 to 5 of 5

Thread: Qlabel e jpeg

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

    Default Qlabel e jpeg

    Hello,

    is it possible to generate a qlabel and to see into the label an image jpeg?

    Please, write two lines in qt4 very simple, so I can copy and paste in my application to look an image jpg on my form.

    I am not able to do it!!!

    If I design the form with the proprierty "pixmap" and select the file jpeg, I see the file on my qlabel, but when I start the program, the image is not present on the qlabel.

    Help me, plese.

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

    Default Re: Qlabel e jpeg

    Qt Code:
    1. int main(int argc, char **argv) {
    2. QApplication app(argc, argv);
    3. QLabel *label = new QLabel;
    4. label->setPixmap(QPixmap("/usr/share/icons/default.kde4/128x128/actions/voicecall.png"));
    5. label->show();
    6. app.exec();
    7. delete label;
    8. return 0;
    9. }
    To copy to clipboard, switch view to plain text mode 
    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 e jpeg

    Thanks for the answer.

    I'm working on Windows, and the file jpg is on the root.




    #include <QtGui/QApplication>
    #include "mainwindow.h"
    #include <QLabel>
    #include <QPixmap>

    int main(int argc, char **argv)
    {
    QApplication app(argc, argv);
    QLabel *label = new QLabel;
    label->setPixmap(QPixmap("c:\presentation.jpg"));
    label->show();
    app.exec();
    delete label;
    return 0;
    }



    When I start the program, it appear a empty window with no label and no image......

    And now?

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

    Default Re: Qlabel e jpeg

    You know that you should escape backslashes in strings, right?
    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.


  5. #5
    Join Date
    May 2009
    Location
    Canada
    Posts
    163
    Thanks
    7
    Thanked 20 Times in 20 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Windows Android

    Default Re: Qlabel e jpeg

    Note that,
    If you always use "/", Qt will translate your paths to conform to the underlying operating system.
    (from the documentation for QDir::separator())

Similar Threads

  1. Replies: 1
    Last Post: 29th September 2009, 19:44
  2. QLabel bug??? Please help
    By jwieland in forum Qt Programming
    Replies: 3
    Last Post: 3rd April 2009, 20:04
  3. Replies: 1
    Last Post: 2nd August 2008, 15:46
  4. Qlabel
    By dragon in forum Qt Programming
    Replies: 10
    Last Post: 7th August 2007, 16:46
  5. QLabel
    By xapek in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2007, 10:27

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
  •  
Qt is a trademark of The Qt Company.