satoshi
7th May 2009, 12:17
Hi all,
I've a strange problem setting a QPixmap on a QLabel. I call a thread which sets the QPixmap on the QLabel. That's the code I'm using:
QPixmap *pxm = new QPixmap((QString("C:/image.jpg")));
if(!pxm->isNull())
{
printf("Pixmap isn't null! %dx%d\n", this->width(), pxm->height());
this->a->w->imageLabel->setImage(this->pxm);
}
else
{
printf("Pixmap is null!\n");
}
If I put it in the run() function of the thread, it clears the image that the imageLabel was showing before (you see a gray background). If I put it in the costructor of the thread instead, it works. But in both it prints:
"Pixmap isn't null! 320x274
I set the image. 320x274 32 (183, 175, 172)"
Thats the method setImage of imageLabel:
void G2_ImageLabel::setImage(QPixmap *pxm)
{
QImage img = pxm->toImage();
QRgb px = img.pixel(10, 10);
printf("I set the image. %dx%d %d (%d, %d, %d)\n", pxm->width(), pxm->height(), pxm->depth(), qRed(px), qGreen(px), qBlue(px));
this->setPixmap(*pxm);
}
I don't know what I'm doing wrong. Please help me!
Thank you, Dario
(sorry for my english)
I've a strange problem setting a QPixmap on a QLabel. I call a thread which sets the QPixmap on the QLabel. That's the code I'm using:
QPixmap *pxm = new QPixmap((QString("C:/image.jpg")));
if(!pxm->isNull())
{
printf("Pixmap isn't null! %dx%d\n", this->width(), pxm->height());
this->a->w->imageLabel->setImage(this->pxm);
}
else
{
printf("Pixmap is null!\n");
}
If I put it in the run() function of the thread, it clears the image that the imageLabel was showing before (you see a gray background). If I put it in the costructor of the thread instead, it works. But in both it prints:
"Pixmap isn't null! 320x274
I set the image. 320x274 32 (183, 175, 172)"
Thats the method setImage of imageLabel:
void G2_ImageLabel::setImage(QPixmap *pxm)
{
QImage img = pxm->toImage();
QRgb px = img.pixel(10, 10);
printf("I set the image. %dx%d %d (%d, %d, %d)\n", pxm->width(), pxm->height(), pxm->depth(), qRed(px), qGreen(px), qBlue(px));
this->setPixmap(*pxm);
}
I don't know what I'm doing wrong. Please help me!
Thank you, Dario
(sorry for my english)