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);
关于c++ - 如何重新缩放图像并将其设置为 QWidget?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8805176/