QWidget 类设置背景图片
法1.
setStyleSheet("border-image:url(://test.png)");
setStyleSheet(QString("border-image:url(:%1)").arg(path));
默认就是平铺填满整个区域
法2.
QPixmap pic(CONFIG->resource_path + imagePath);
QPalette palette = w->palette();
QPixmap scaled = pic.scaled(w->size(),Qt::IgnoreAspectRatio,Qt::SmoothTransformation);
palette.setBrush(w->backgroundRole(), QBrush(scaled));
w->setPalette(palette);
w->setAutoFillBackground(true); // 这句要加上
这种不能平铺,是重复的,不好用
法3.
再添加一个QLabel,设置QLabel的图片
picLabel->setPixmap(pic);////只能显示原来的部分图片,不是整体缩放的
picLabel->setScaledContents(true);//这句要加上不然就不能平铺了
法4
picLabel->setPixmap(pixmap.scaled(control->size()));//显示缩放的完整的图片,但模糊
法5
picLabel->setStyleSheet(QString("QLabel { background-image: url('%1');background-size: cover;}").arg(pic));//重复显示