PDA

View Full Version : Displaying a QImage on the screen



nuser
9th April 2010, 16:21
Hello,

I have an unsigned char pointer to an image codified in 24 bits RGB. I tried to display it on the screen through the following code.

void GLWidget::paintEvent(QPaintEvent *event)
{
QImage qi(buff, 640, 480, QImage::Format_RGB888);
QPainter painter;
painter.begin(this);
painter.drawImage(event->rect(), qi);
painter.end();
}

When I execute this code, the screen is black. However, if I save the QImage to a *.png file and load it again, it works. The format of the QImage when I loaded from the file is QImage::Format_RGB32. I tried to convert the original one to this format, but still not working.

Any ideas? Is there any other way to display an image on the screen?

Thank you very much!

aamer4yu
9th April 2010, 20:51
The simplest way to show an image is through QLabel::setPixmap