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)
但小部件不显示任何图像.
您是否只是想在窗口小部件中显示缩放图像?我不认为在画笔中设置图像然后在调色板中设置画笔是正确的方法.
您可以使用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)
归档时间: |
|
查看次数: |
5410 次 |
最近记录: |