当前位置:网站首页>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,以上便是本文的全部内容了,如果对你有所帮助,记得点个赞哟~
边栏推荐
猜你喜欢
随机推荐
R language ggplot2 visualization: use the ggboxplot function of the ggpubr package to visualize the grouped box plot, use the ggpar function to change the graphical parameters (caption, add, modify th
border控件的使用
Ubantu专题4:xshell、xftp连接接虚拟机以及设置xshell复制粘贴快捷键
工程水文学试卷
Synchronized和volatile 面试简单汇总
Doing things software development - the importance of law and understanding of reasonable conclusions
The use of border controls
mysql black window ~ build database and build table
JVM parameter analysis Xmx, Xms, Xmn, NewRatio, SurvivorRatio, PermSize, PrintGC "recommended collection"
双边滤波加速「建议收藏」
update data table update
OPPO在FaaS领域的探索与思考
Efficient use of RecyclerView Section 2
"Autumn Recruitment Series" MySQL Interview Core 25 Questions (with answers)
button控件的使用
R language ggplot2 visualization: use the ggboxplot function of the ggpubr package to visualize the box plot, use the font function to customize the font size, color, style (bold, italic) of the legen
Emmet syntax
How useful is four-quadrant time management?
Linux查看redis版本(查看mongodb版本)
四象限时间管理有多好用?









