Solved No show of QPixmap
-
@JKSH The return is:
("bmp", "cur", "gif", "ico", "jpeg", "jpg", "pbm", "pgm", "png", "ppm", "xbm", "xpm") -
-
What if you set the pixmap directly on the QLabel rather than using a brush in the palette ?
-
@Stan-Huang
It's not quite clear from the code you posted, but are you sure thatpalette_RoadFault
is not set to something invalid somewhere else in your code, and thatpalette_RoadFault
persists outside the scope of your function?QBrush expects a const reference to a QPixmap, I don't think it will take ownership or make a copy of the QPixmap for drawing.
-
@SGaist I did it but still doesn't work:
ui->label->setGeometry(20,20,60,20);
ui->label->setPixmap(pixmap_RoadFault);
ui->label->show(); -
@SGaist I did but still doesn't work:
ui->label->setGeometry(20,20,60,20); ui->label->setPixmap(pixmap_RoadFault); ui->label->show();
-
Don't set the geometry since you have a designer based UI, that will let QLabel in its original place to show the pixmap.
If it's still not working, then test again with another image. And if possible, share that file with us so that we can test it on our ends.
-
That's my mistake. A clear statement was executed right after ->show() was executed. That's, show() did its good job, but the shown picture was cleaned immediately. I apologize for my mistake.
-
@Stan-Huang said in No show of QPixmap:
That's my mistake. A clear statement was executed right after ->show() was executed. That's, show() did its good job, but the shown picture was cleaned immediately. I apologize for my mistake.
I'm glad to hear that you've got it working now.
Like I said 10 days ago, it's best to use simple examples. I even wrote a full program for you that works, but you didn't use it.
-
@JKSH Yes. I didn't do it 10 days ago due to 9-day lunar new year vacation. Thanks very much.