当前位置:网站首页>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,以上便是本文的全部内容了,如果对你有所帮助,记得点个赞哟~
边栏推荐
- Internet banking stolen?This article tells you how to use online banking safely
- 【MySQL】Mysql范式及外键作用
- R语言向前或者向后移动时间序列数据(自定义滞后或者超前的期数):使用dplyr包中的lag函数将时间序列数据向前移动一天(设置参数n为正值)
- Synchronized and volatile interview brief summary
- 为什么黑客领域几乎一片男生?
- type of timer
- MySQL database operations
- 腾讯云部署----DevOps
- 四象限时间管理有多好用?
- 全新宝马3系上市,安全、舒适一个不落
猜你喜欢

Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键

Word table to Excel

After Grafana is installed, the web opens and reports an error

Synchronized and volatile interview brief summary

TRACE32 - SNOOPer-based variable logging

type of timer

【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发

Efficient use of RecyclerView Section 1

mysql black window ~ build database and build table

Browser's built-in color picker
随机推荐
Female service community product design
工程力学复习资料
Precautions and solutions when SIGABRT error is reported
Efficient use of RecyclerView Section 3
OPPO在FaaS领域的探索与思考
R语言计算时间序列数据的移动平均值(滚动平均值、例如5日均线、10日均线等):使用zoo包中的rollmean函数计算k个周期移动平均值
Oracle dynamically registers non-1521 ports
[MySQL] Mysql paradigm and the role of foreign keys
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(caption、添加、修改可视化图像的题注、脚注内容)
工程流体力学复习
The normal form of the database (first normal form, second normal form, third normal form, BCNF normal form) "recommended collection"
WPF项目--控件入门基础用法,必知必会XAML
Gorm—Go language database framework
【CUDA学习笔记】初识CUDA
Gorm—Go语言数据库框架
What is the difference between BI software in the domestic market?
Emmet 语法
ASP.NET Core 产生连续 Guid
修改SQL语言实现Mysql 多表关联查询优化
工程水文学试卷