当前位置:网站首页>自定义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”,获取资源链接。有任何疑问也可以公众号里留言咨询。
边栏推荐
- The person who goes to and from work on time and never wants to work overtime has been promoted in front of me
- Modification of annotation based three-tier project and the way of adding package scanning
- roLabelImg转DATO格式数据
- Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
- How to install Office2010 installation package? How to install Office2010 installation package on computer
- Soft link & hard link
- Arfoundation starts from scratch 3- create an arfoundation project
- What servers are needed to build mobile app
- Original code, inverse code, complement code
- How to monitor micro web services
猜你喜欢
ARFoundation从零开始3-创建ARFoundation项目
The person who goes to and from work on time and never wants to work overtime has been promoted in front of me
自贸经济中架起的“隐形桥梁”:国货精品与中国AI力量
Getting started with solidity
SM integration is as simple as before, and the steps are clear (detailed)
虚拟偶像的歌声原来是这样生成的!
The method and detailed code of automatically pop-up and QQ group when players visit the website
Unity metaverse (III), protobuf & socket realize multi person online
Numpy Foundation
后置通知的流程分析与功能实现有哪些内容你还记得吗?
随机推荐
Self join and joint query of MySQL
传奇如何一台服务器配置多个版本微端更新
基于注解的三层项目的改造及添加包扫描的方式
开区网站打开自动播放音乐的添加跟修改教程
js(forEach)出现return无法结束函数的解决方法
Operator operation list of spark
2021-10-11
How to solve the problem of configuring the progress every time Office2010 is opened?
三层项目的架构分析及构造方法的参数名称注入
About realizing page Jump of website in Servlet
Excel怎么筛选出自己想要的内容?excel表格筛选内容教程
Open source Huizhi creates the future | the openeuler sub forum of 2022 open atom global open source summit was successfully held
ARFoundation从零开始9-AR锚点(AR Anchor)
玩家访问网站自动弹窗加QQ群方法以及详细代码
[untitled]
Lenovo Savior r7000+ add ssd+ copy and partition the information of the original D disk to the new SSD
office2010每次打开都要配置进度怎么解决?
Arfoundation starts from zero 9-ar anchor
scikit-learn——机器学习应用开发的步骤和理解
【微信小程序--解决display:flex最后一行对齐问题。(不连续排列会分到两边)】