Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I rescale an image and set it to QWidget?

Tags:

c++

qt

meego

QPixmap pic("../image.jpg");

setAutoFillBackground(true);
QPalette palette;
QPixmap scaled=pic.scaled ( 800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation );

palette.setBrush(QPalette::Window, QBrush(scaled));

//this->setPalette(palette);
QWidget *w= new QWidget(this);
w->setGeometry(0,0,800,480);
w->show();
w->setPalette(palette); 

But the widget does not show any image.

like image 224
Thorin Avatar asked Oct 24 '25 16:10

Thorin


1 Answers

Are you just trying to show the scaled image in a widget? I don't think setting the image in the brush and then setting the brush in the palette is the correct approach.

You can just use a QLabel to show an image in a widget. Like this:

QPixmap pic("../image.png");
QPixmap scaled=pic.scaled ( 800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation );

QLabel *label = new QLabel(this);
label->setPixmap(scaled);
like image 136
Dusty Campbell Avatar answered Oct 27 '25 05:10

Dusty Campbell