当前位置:网站首页>自定义Qml控件:ImageButton
自定义Qml控件:ImageButton
2022-07-29 05:07:00 【上官宏竹】
效果
我们来定义一个ImageButton控件,即Button上增加显示一个Image图片,既有Button的点击事件,也同时增加三种状态:正常状态、悬停状态、按压状态。
效果如下:
正常 <-> 悬停:
按压效果:
实现思路
定义一个
Rectangle内部包含一个Image,用来显示图片Rectangle{ Image { id:bk_image anchors.fill: parent } }图片填充整个
Rectangle,也可以增加对Rectangle边缘的修饰,这个依个人项目而定。定义一个
MouseArea用来接收鼠标事件接收:
entered、exited、pressed三种事件,在对应的事件中改变Rectangle的state值,从而触发状态转变。定义一个
states用来做状态转换时更新图片states的具体用法可以参考 Qml类型:State状态 一章。在每一个状态中我们需要改变两个东西:一个是
Image图片源,另一个是Rectangle的透明度。那么每一个State需要两个PropertyChanges,形式如下:State { name: "normal" // 状态名称 PropertyChanges { target: bkImage // 目标控件ID source: rootRect.normal_url // 需要改变的目标控件的属性 } PropertyChanges{ target: rootRect opacity: noramlOpacity } }
完整实现可以微信搜索公众号:“上官宏竹”,或者扫下面的二维码,关注并回复:“ImageButton”,获取资源链接。有任何疑问也可以公众号里留言咨询。
边栏推荐
- SQL log
- The representation of time series analysis: is the era of learning coming?
- 自贸经济中架起的“隐形桥梁”:国货精品与中国AI力量
- AttributeError: ‘module‘ object has no attribute ‘create_connection‘
- Functions in MySQL statements
- Pivot table of odoo development tutorial
- sql日志
- 后置通知的流程分析与功能实现有哪些内容你还记得吗?
- Do you remember the process analysis and function implementation of post notification?
- Google gtest事件机制
猜你喜欢

Excel怎么筛选出自己想要的内容?excel表格筛选内容教程

Understand activity workflow

Soft link & hard link

Functions in MySQL statements

学习数据库的第一个程序

SM整合原来这么简单,步骤清晰(详细)

MySQL many to many relationship, grouping and splicing to query multiple data to one data

向往的开源之多YOUNG新生 | 从开源到就业的避坑指南来啦!

Glory 2023 push, push code ambubk

Jackson解析JSON详细教程
随机推荐
sql日志
P5714 [deep foundation 3. Case 7] obesity
Self join and joint query of MySQL
On AspectJ framework
Apache POI实现Excel导入读取数据和写入数据并导出
What servers are needed to build mobile app
关于servlet中实现网站的页面跳转
ODOO开发教程之透视表
roLabelImg转DATO格式数据
Learn the first program of database
[file download] easyexcel quick start
Raspberry pie 4B + Intel neural computing stick (stick2) +yolov5 feasibility study report
关于thymeleaf的配置与使用
The person who goes to and from work on time and never wants to work overtime has been promoted in front of me
Scikit learn -- steps and understanding of machine learning application development
【文件下载】Easyexcel快速上手
MySQL sorts the queried result set according to the specified sequence
How to make the characters in the photos laugh? HMS core video editing service one click smile function makes people smile more naturally
Use annotation test in idea
VirtualBox has expanded the capacity of virtual hard disk (without modifying the original data)