Qt 编程指南 7 添加背景

#include "QT_Text1.h"
#include <QtWidgets/QApplication>
#include <QBitmap>


int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

	

	QT_Text1 w;

	QPixmap pixmap("images/timg2.jpg");   //  读取图片
	QPalette   palette;
	palette.setBrush(w.backgroundRole(), QBrush(pixmap));  // 将图片设置在指定窗口
	w.setPalette(palette);
	w.setMask(pixmap.mask());  //可以将图片中透明部分显示为透明的
	w.setAutoFillBackground(true);   // 自动充满
	w.show();


	return a.exec();
}

  图片的存取位置 images/timg2

 this->setWindowOpacity(1); //窗口整体透明度,0-1 从全透明到不透明
    this->setWindowFlags(Qt::FramelessWindowHint); //设置无边框风格
    this->setAttribute(Qt::WA_TranslucentBackground); //设置背景透明,允许鼠标穿透

  

原文地址:https://www.cnblogs.com/kekeoutlook/p/7475554.html