PDA

View Full Version : refreshing QPixmap



Wojtek.wk
18th April 2010, 02:41
Hi!
Is it possible to refresh the picture viewed by QPixmap? I have the QPixmap object with given picture and when I'll click the button it should refresh (because in the meantime this picture has changed)... I've looked in API for something like this, but with no result.
Thanks in advance!

Talei
18th April 2010, 03:00
QPixmap in representation of data in the mem, so you don't display pixmap but view pixmap in i.e. qlabel. Do something like this:

QPixmap px;
px.load("image1.ext");
ui->label->setPixmap(px);

//and on button press
px.load("image2.ext");
//or
//QByteArray ByteArrayImage;
//px.loadFromData( ByteArrayImage );
ui->label->setPixmap(px);

EDIT: You could use, on button press, something like this also:

ui->label->setScaledContents( false );
ui->label->update( ui->label->rect() );
ui->label->setScaledContents( true );
or repaint. If you don't setScaledContents(false) then true image don't show, assuming that scaledContents was true.