3
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); 

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

4

2 回答 2

7

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

您可以只使用 QLabel 在小部件中显示图像。像这样:

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

QLabel *label = new QLabel(this);
label->setPixmap(scaled);
于 2012-01-10T17:30:49.383 回答
0

您在设置调色板之前显示小部件。先尝试设置调色板。

如果这没有帮助,请尝试指定完整的文件路径。

于 2018-09-19T16:14:26.417 回答