目录
1.设置窗口半透明,子控件不透明
先在窗口的构造函数调用下面的函数将窗口设置为透明状态
setAttribute(Qt::WA_TranslucentBackground, true);
然后重写paintEvent函数,代码如下
QPainter pater(this);
///<QColor的最后一个是表示透明度,最大是255不透明,0表示全透明,按照这个比例去计算
panter.fillRect(this->rect(), QColor(0, 0, 0, 204));
2.将窗口和控件都设置为半透明
///<下边函数的参数表示透明度,透明度为0-1,分为10个等级,0为全透明,1为不透明
setWindowOpacity(0.8);
3.窗口整体不透明,局部透明
在Paint事件中使用Clear模式绘图
QPainter p(this);
p.setCompositionMode( QPainter::CompositionMode_Clear );
p.fillRect( 10, 10, 300, 300, Qt::SolidPattern );