PDA

View Full Version : Pixmap do not getting set in label



Niamita
20th January 2012, 12:32
Hi

Might be this question i should not ask but i am not understanding what is wrong with this. I am trying to set a pixmap to a label (here label is my custom label class in which i inherit paintEvent() and mousePressEvent()) , but it is not getting display. I checked whether image is loaded or not , i found that image is loaded correctly.
My code for setting pixmap is


QPixmap image1(":/buttonn.png");
this.setPixmap(QPixmap::fromImage(image1));
if(image1.isNull()){
label->setText("null pic");
}

Thanks.

Lykurg
20th January 2012, 12:39
QPixmap image1(":/buttonn.png");
this.setPixmap(QPixmap::fromImage(image1));
? image1 is already a pixmap. So simple use
this.setPixmap(image1);

Niamita
20th January 2012, 12:58
thank you Lykurg for immediate response, but i am still not successful in setting pixmap to label.

Lykurg
20th January 2012, 13:01
Then please post a little bit more code or even better, make a compilable example reproducing your problem. Because the error seems not to be in your posted code.

Niamita
20th January 2012, 13:10
Ok
i have a class in which i make instance of my custom label class.
In my custom label claas i am trying to set pixmap in my class constructor with above posted code. i override paintEvent() and mousePressEvent() method only in that class excepting setting pixmap.
I am not getting what i am doing wrong.

Lykurg
20th January 2012, 13:13
how does the paintEvent() looks like? Maybe you simply do not draw the pixmap? This works normaly fine:
class MyLabel : public QLabel
{
Q_OBJECT
MyLabel(...)
{
setPixmap("...")
}
};

Niamita
20th January 2012, 13:23
i solved the problem by setting a label as its child.
well thanks Lykurg for responsing.
Thank you.