当前位置:网站首页>自定义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”,获取资源链接。有任何疑问也可以公众号里留言咨询。
边栏推荐
- ARFoundation从零开始9-AR锚点(AR Anchor)
- How does excel filter out the content you want? Excel table filtering content tutorial
- How to add traffic statistics codes to the legendary Development Zone website
- Mysql把查询到的结果集按指定顺寻进行排序
- Spark的算子操作列表
- 7.2-function-overloading
- SM integration is as simple as before, and the steps are clear (detailed)
- How to set row height and column width in excel? The method of setting row height and column width in Excel
- The method and detailed code of automatically pop-up and QQ group when players visit the website
- JS daily question (10)
猜你喜欢

Five correlation analysis, one of the most important skills of data analysts

TCP三次握手四次挥手

传奇服务端如何添加地图

Big silent event Google browser has no title

浅谈AspectJ框架

Deadlock analysis using jstack, jconsole, and jvisualvm
![[untitled]](/img/6c/df2ebb3e39d1e47b8dd74cfdddbb06.gif)
[untitled]

Network Security Learning - Intranet Security 1

传奇开区网站如何添加流量统计代码

< El table column> place multiple pictures
随机推荐
Youxuan database failed to start and reported network error
2022年SPSSPRO认证杯数学建模B题第二阶段方案及赛后总结
pytorch学习笔记
P1009 [noip1998 popularization group] sum of factorials
传奇服务端如何添加地图
SM integration is as simple as before, and the steps are clear (detailed)
AttributeError: ‘module‘ object has no attribute ‘create_connection‘
搭建手机APP需要用到什么服务器
roLabelImg转DATO格式数据
Use annotation test in idea
Introduction of JDBC preparestatement+ database connection pool
TMUX essays
Open the tutorial of adding and modifying automatically playing music on the open zone website
Unity metaverse (III), protobuf & socket realize multi person online
IDEA中使用注解Test
Excel怎么筛选出自己想要的内容?excel表格筛选内容教程
ARFoundation入门教程7-url动态加载图像跟踪库
Open source Huizhi creates the future | the openeuler sub forum of 2022 open atom global open source summit was successfully held
Young freshmen yearn for more open source | here comes the escape guide from open source to employment!
tmux随笔