当前位置:网站首页>Qt practical cases (54) - using transparency QPixmap design pictures
Qt practical cases (54) - using transparency QPixmap design pictures
2022-07-31 15:33:00 【wendy_ya】
一、项目介绍
本文介绍利用QPixmapDesign image transparency,You can see the progress bar below the drag,Used to control the transparency of the image above.
二、项目基本配置
新建一个Qt案例,项目名称为“TransparencyTest”,基类选择“QWidget”,点击选中创建UI界面复选框,完成项目创建.
三、UI界面设置
UI界面如下:
序号 | 名称 | 类型 | 属性 |
---|---|---|---|
① | label_photo | QLabel | / |
② | slider | QSlider | minimum:0;maximum:255; |
四、主程序实现
4.1 widget.h头文件
The slider movement slot function needs to be declared in the header file:
右键——>滑动条——>sliderMoved:
我这里是:
private slots:
void on_Slider_sliderMoved(int position);
4.2 widget.cpp源文件
The source file first sets the background in the constructorlabel的图片,然后设置label位置,Set the initial position of the slider to the far right:
//设置窗口大小
setFixedSize(800,600);
//设置背景label的图片
QPixmap pix(":/test.jpg");
ui->label_photo->setPixmap(pix);
//设置lable位置
ui->label_photo->setScaledContents(true);
ui->label_photo->setGeometry(10,10,200,150);
ui->label_photo->raise();
ui->label_photo->show();
//Set the initial slider position to the far right
ui->Slider->setValue(255);
Define the slider slot function:
void Widget::on_Slider_sliderMoved(int position)
{
//Sets the transparency of the new image
QPixmap pix1(":/test.jpg");
QPixmap temp(pix1.size());
temp.fill(Qt::transparent);
QPainter p1(&temp);
p1.setCompositionMode(QPainter::CompositionMode_Source);
p1.drawPixmap(0, 0, pix1);
p1.setCompositionMode(QPainter::CompositionMode_DestinationIn);
//根据QColorThe fourth parameter in sets the transparency,此处position的取值范围是0~255
p1.fillRect(temp.rect(), QColor(0, 0, 0, position));
p1.end();
pix1 = temp;
ui->label_photo->setPixmap(pix1);
}
五、效果演示
完整效果如下:
如果没有看懂的话,完整代码可以参考:https://download.csdn.net/download/didi_ya/86268287
ok,以上便是本文的全部内容了,如果对你有所帮助,记得点个赞哟~
边栏推荐
- Ubantu project 4: xshell, XFTP connected the virtual machine and set xshell copy and paste the shortcut
- MySQL基础篇【单行函数】
- Precautions and solutions when SIGABRT error is reported
- 删除表格数据或清空表格
- 01 邂逅typescript,环境搭建
- Why don't you make a confession during the graduation season?
- Synchronized和volatile 面试简单汇总
- Matlab matrix basic operations (definition, operation)
- How useful is four-quadrant time management?
- hough变换检测直线原理(opencv霍夫直线检测)
猜你喜欢
.NET 20周年专访 - 张善友:.NET 技术是如何赋能并改变世界的
Synchronized and volatile interview brief summary
Dialogue with Zhuang Biaowei: The first lesson of open source
TRACE32 - SNOOPer-based variable logging
The use of border controls
mongo进入报错
长得很怪的箱图
TRACE32——基于SNOOPer的变量记录
TextBlock控件入门基础工具使用用法,取上法入门
C language "the third is" upgrade (mode selection + AI chess)
随机推荐
做事软件开发-法的重要性所在以及合理结论的认识
Internet banking stolen?This article tells you how to use online banking safely
TRACE32——基于SNOOPer的变量记录
JVM参数解析 Xmx、Xms、Xmn、NewRatio、SurvivorRatio、PermSize、PrintGC「建议收藏」
Deployment application life cycle and Pod health check
Oracle dynamically registers non-1521 ports
MySQL的相关问题
实现防抖与节流函数
Kubernetes常用命令
ASP.NET Core 产生连续 Guid
Use of radiobutton
435. 无重叠区间
Dialogue with Zhuang Biaowei: The first lesson of open source
Matlab matrix basic operations (definition, operation)
R语言计算时间序列数据的移动平均值(滚动平均值、例如5日均线、10日均线等):使用zoo包中的rollmean函数计算k个周期移动平均值
"Autumn Recruitment Series" MySQL Interview Core 25 Questions (with answers)
ansible学习笔记02
修改SQL语言实现Mysql 多表关联查询优化
Snake Project (Simple)
01 Encounter typescript, build environment