如何重新缩放图像并将其设置为QWidget?

Tho*_*rin 3 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); 
Run Code Online (Sandbox Code Playgroud)

但小部件不显示任何图像.

Dus*_*ell 5

您是否只是想在窗口小部件中显示缩放图像?我不认为在画笔中设置图像然后在调色板中设置画笔是正确的方法.

您可以使用QLabel在窗口小部件中显示图像.像这样:

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

QLabel *label = new QLabel(this);
label->setPixmap(scaled);
Run Code Online (Sandbox Code Playgroud)