
正文
3.Qt GUI中一些操作记录
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
一、如何在Widget中利用代码添加背景图片
this->setAutoFillBackground(true); //
QPalette palette = this->palette();
palette.setBrush(QPalette::Window,
QBrush(QPixmap(":/images/bg2.jpg").scaled(// 缩放背景图.
this->size(),
Qt::IgnoreAspectRatio,
Qt::SmoothTransformation)));
this->setPalette(palette);
二、如何在QLabel中缩放图片
void text::setpixmap(const QString &filename, QLabel *label)
{
QImage Image;
Image.load(filename);
QPixmap pixmap = QPixmap::fromImage(Image);
int with = label->width();
int height= label->height();
QPixmap fitpixmap = pixmap.scaled(with,height,Qt::KeepAspectRatio,Qt::SmoothTransformation);//按比例缩放
// QPixmap fitpixmap = pixmap.scaled(with,height,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);//饱满填充
label->setPixmap(fitpixmap);
}
三、





