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

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

label = new QLabel(this);

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));
// 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...

16th December 2019, 18: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.