一、如何在Widget中利用代码添加背景图片
1 this->setAutoFillBackground(true); // 2 QPalette palette = this->palette(); 3 palette.setBrush(QPalette::Window, 4 QBrush(QPixmap(":/images/bg2.jpg").scaled(// 缩放背景图. 5 this->size(), 6 Qt::IgnoreAspectRatio, 7 Qt::SmoothTransformation))); 8 this->setPalette(palette);
二、如何在QLabel中缩放图片
1 void text::setpixmap(const QString &filename, QLabel *label) 2 { 3 QImage Image; 4 Image.load(filename); 5 QPixmap pixmap = QPixmap::fromImage(Image); 6 int with = label->width(); 7 int height= label->height(); 8 QPixmap fitpixmap = pixmap.scaled(with,height,Qt::KeepAspectRatio,Qt::SmoothTransformation);//按比例缩放 9 // QPixmap fitpixmap = pixmap.scaled(with,height,Qt::IgnoreAspectRatio,Qt::SmoothTransformation);//饱满填充 10 label->setPixmap(fitpixmap); 11 }
三、