PDA

View Full Version : Qlabel pixmap and resize pixmap, and repaint() not working



sevketk
15th December 2019, 18:00
Hi . my code is



back.load(":/images/back.png");
label = new QLabel(this);
label->setGeometry(0,0,142,192);

label->setPixmap(back);
setStyleSheet("background-color:red"); // so far so good
// but i want to change size pixmap after load (for example onclick event)
label->pixmap()->scaled(QSize(100, 297));
label->repaint();
// noting change size with or another



I wantto change pixmap width after loading in label , because I use two pixmap for one label. I want to the pixmap of label inside to change , Whichever it can. I mean , what's inside pixmap that moment
in other words, I want to change size which pixmap is present in the label, without knowing what pixmap is...

d_stranz
16th December 2019, 17:31
label->pixmap()->scaled(QSize(100, 297))

This code does nothing to the pixmap that is stored on the label. label->pixmap() returns a pointer to the pixmap on the label. QPixmap::scaled() returns a scaled copy of that pixmap, which is immediately thrown away as soon as the statement ends.

What you want is this:



label->setPixmap( label->pixmap()->scaled( QSize( 100, 297 ) ) );


You do not need the repaint() call; the label will automatically repaint itself after a new pixmap is set.