// [1] 图片不重复,可自由缩放
ui->label->setStyleSheet("QLabel{"
"border-image:url(:/images/bd.png) 4 4 4 4 stretch stretch;"
"}");
// [2] 图片不重复,大小固定
ui->label_2->setStyleSheet("QLabel{"
"background-image:url(:/images/bd.png);"
"background-position:top right;"
"background-origin:content;"
"background-repeat:none;"
"}");
// [3] 图片不重复,可设置缩放比例,不可动态缩放
QImage* img = new QImage;
img->load(QString(":/images/bd.png"));
QImage scaledimg;
scaledimg = img->scaled(ui->label_3->width(),ui->label_3->height(),Qt::KeepAspectRatio);
ui->label_3->setPixmap(QPixmap::fromImage(scaledimg));
QLabel中设置背景图片的3种方法
猜你喜欢
转载自blog.csdn.net/weixin_39568531/article/details/104340289
今日推荐
周排行