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);//这句要加上不然就不能平铺了