题
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);
但是小部件没有显示任何图像。
解决方案
您只是想在小部件中显示缩放图像吗?我不认为将图像设置在刷子中,然后在调色板中设置刷子是正确的方法。
您可以只使用Qlabel在小部件中显示图像。像这样:
QPixmap pic("../image.png");
QPixmap scaled=pic.scaled ( 800, 480, Qt::IgnoreAspectRatio, Qt::FastTransformation );
QLabel *label = new QLabel(this);
label->setPixmap(scaled);
其他提示
在设置调色板之前,您正在显示小部件。尝试先设置调色板。
如果没有帮助,请尝试指定完整的文件路径。
不隶属于 StackOverflow