日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Qt實現部件透明及陰影效果的示例代碼_C 語言

作者:CAccept ? 更新時間: 2022-04-10 編程語言

透明效果

情況一

 //窗口整個透明屬性,取值為0-1,0為全透明
 setWindowOpacity(0.5);

在這里插入圖片描述

情況二

 //部件不透明,窗體背景完全透明,以下兩個函數必須配合使用
 setWindowFlags(Qt::FramelessWindowHint);//窗口無邊框
 setAttribute(Qt::WA_TranslucentBackground);//背景透明

在這里插入圖片描述

情況三

//單個部件設置透明
//需要添加頭文件#include<QGraphicsOpacityEffect>
QGraphicsOpacityEffect*opacityEffect=new QGraphicsOpacityEffect;
opacityEffect->setOpacity(0.1);  //0為完全透明,1為不透明
ui->label->setGraphicsEffect(opacityEffect);

在這里插入圖片描述

情況四

窗口半透明,部件不透明:需要重寫paintEvent

setWindowFlags(Qt::FramelessWindowHint);   //窗口無邊框
setAttribute(Qt::WA_TranslucentBackground);//背景透明
//重寫繪圖事件
void MainWindow::paintEvent(QPaintEvent *event)
{
    QPainter painter(this);
    painter.fillRect(rect(),QColor(255,255,255,200));//rect:填充矩形區域+rgb值+透明度為100
}

在這里插入圖片描述

陰影效果

要添加頭文件#include<QGraphicsDropShadowEffect>

//陰影效果
QGraphicsDropShadowEffect*shadowEffect=new QGraphicsDropShadowEffect;
//陰影色,透明色
shadowEffect->setColor(QColor(100,100,100));
shadowEffect->setBlurRadius(20);//陰影模糊半徑
shadowEffect->setOffset(20);    //陰影偏移值
ui->label->setGraphicsEffect(shadowEffect);

在這里插入圖片描述

原文鏈接:https://blog.csdn.net/Jacksqh/article/details/122722827

欄目分類
最近更新