1. 程式人生 > 其它 >給QMainWindow新增背景圖片並拉伸

給QMainWindow新增背景圖片並拉伸

問題:無論是使用樣式表還是設定brush都無法解決QMainWindow或QWidget背景拉伸問題

解決方法:只能在c++中 新建一個label並放置到底層

	//顯示背景圖片
	QPixmap pixmap(":/Resources/BackgroundImg.jpg");
	QLabel* label = new QLabel(this);
	label->setPixmap(pixmap.scaled(QSize(geometry().width(), geometry().height()), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)
); label->resize(QSize(geometry().width(), geometry().height())); label->lower();