Results 1 to 5 of 5

Thread: How do I set an QImage on a QLabel?

  1. #1
    Join Date
    Jul 2010
    Posts
    72
    Thanks
    35
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default How do I set an QImage on a QLabel?

    Hi

    How do I set an QImage on a QLabel?
    I'm really stuck!

    Cheers

  2. #2
    Join Date
    Mar 2008
    Location
    France
    Posts
    149
    Thanks
    2
    Thanked 21 Times in 21 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I set an QImage on a QLabel?

    Try this:
    Qt Code:
    1. int main(int argc, char** argv)
    2. {
    3. QApplication app(argc, argv);
    4. QPixmap image("image.jpg");
    5. QLabel imageLabel();
    6. imageLabel.setPixmap(image);
    7. label.show();
    8. return app.exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    QImage is designed and optimized for I/O, and for direct pixel access and manipulation, while QPixmap is designed and optimized for showing images on screen

  3. #3
    Join Date
    Jul 2010
    Posts
    72
    Thanks
    35
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How do I set an QImage on a QLabel?

    I'm trying to use QImage instead of QPixmap, because it is optimized for pixel manipulation.
    I tried to create a QImage:

    QImage image;
    image = QImage(100, 100, QImage::Format_ARGB32);
    image.fill(qRgb(0, 100, 100));

    and then created a QLabel to set the image:

    QLabel *labelImagem=new QLabel;
    labelImagem->setPicture(image);

    but it won't compile. Any suggestions what is going wrong?

    Cheers

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How do I set an QImage on a QLabel?

    What is the error message and what do you make of it? What are the argument types for setPicture()?
    Last edited by ChrisW67; 3rd August 2010 at 03:49.

  5. #5
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How do I set an QImage on a QLabel?

    Quote Originally Posted by Maluko_Da_Tola View Post
    QLabel *labelImagem=new QLabel;
    labelImagem->setPicture(image);

    but it won't compile. Any suggestions what is going wrong?
    Surprise, surprise. QImage != QPicture! use:
    Qt Code:
    1. l.setPixmap(QPixmap::fromImage(yourImage));
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to Lykurg for this useful post:

    Maluko_Da_Tola (4th August 2010)

Similar Threads

  1. Replies: 1
    Last Post: 29th September 2009, 19:44
  2. display QImage on QLabel
    By akasi in forum Qt Programming
    Replies: 2
    Last Post: 23rd September 2008, 22:48
  3. Replies: 1
    Last Post: 2nd August 2008, 15:46
  4. What's faster: QPixmap-to-QImage or QImage-to-QPixmap
    By forrestfsu in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2006, 17:11
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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.