当前位置:网站首页>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,以上便是本文的全部内容了,如果对你有所帮助,记得点个赞哟~
边栏推荐
- AVH Deployment Practice (1) | Deploying the Flying Paddle Model on Arm Virtual Hardware
- ASP.NET Core generates continuous Guid
- ansible学习笔记02
- Destruction order of thread_local variables
- RecyclerView高效使用第二节
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(legend、修改可视化图像的图例在整图中的位置)
- 7. Summary of common interview questions
- After Grafana is installed, the web opens and reports an error
- Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
- R语言计算时间序列数据的移动平均值(滚动平均值、例如5日均线、10日均线等):使用zoo包中的rollmean函数计算k个周期移动平均值
猜你喜欢

Efficient use of RecyclerView Section 1

Internet banking stolen?This article tells you how to use online banking safely

Kubernetes原理剖析与实战应用手册,太全了

浏览器自带的拾色器

苹果官网样式调整 结账时产品图片“巨大化”

Visualize GraphQL schemas with GraphiQL

Ubantu project 4: xshell, XFTP connected the virtual machine and set xshell copy and paste the shortcut

border控件的使用

RecyclerView的高效使用第一节

01 邂逅typescript,环境搭建
随机推荐
Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
复制延迟案例(1)-最终一致性
mongo进入报错
Vb how to connect mysql_vb how to connect to the database collection "advice"
11 pinia use
"Autumn Recruitment Series" MySQL Interview Core 25 Questions (with answers)
第二届中国PWA开发者日
Tencent Cloud Deployment----DevOps
Kubernetes common commands
435. 无重叠区间
多主复制的适用场景(1)-多IDC
网银被盗?这篇文章告诉你如何安全使用网银
腾讯云部署----DevOps
org.apache.jasperException(could not initialize class org)
R语言ggplot2可视化:使用ggpubr包的ggmaplot函数可视化MA图(MA-plot)、font.legend参数和font.main参数设置标题和图例字体加粗
The R language ggstatsplot package ggbarstats function visualizes bar charts, and adds hypothesis test results (including sample number, statistics, effect size and its confidence interval, significan
How useful is four-quadrant time management?
t-sne 数据可视化网络中的部分参数+
TRACE32 - C source code association
【Meetup预告】OpenMLDB+OneFlow:链接特征工程到模型训练,加速机器学习模型开发