View Full Version : How do I set an QImage on a QLabel?
Maluko_Da_Tola
3rd August 2010, 00:16
Hi
How do I set an QImage on a QLabel?
I'm really stuck!
Cheers
toutarrive
3rd August 2010, 00:22
Try this:
int main(int argc, char** argv)
{
QApplication app(argc, argv);
QPixmap image("image.jpg");
QLabel imageLabel();
imageLabel.setPixmap(image);
label.show();
return app.exec();
}
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
Maluko_Da_Tola
3rd August 2010, 00:58
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
ChrisW67
3rd August 2010, 02:28
What is the error message and what do you make of it? What are the argument types for setPicture()?
Lykurg
3rd August 2010, 06:03
QLabel *labelImagem=new QLabel;
labelImagem->setPicture(image);
but it won't compile. Any suggestions what is going wrong?Surprise, surprise. QImage != QPicture! use:
QLabel l;
l.setPixmap(QPixmap::fromImage(yourImage));
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.