当前位置:网站首页>自定义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”,获取资源链接。有任何疑问也可以公众号里留言咨询。
边栏推荐
- Pytorch learning notes
- Deadlock to be resolved
- 传奇开区网站如何添加流量统计代码
- JS (in ES6) sync & await understanding
- Introduction of JDBC preparestatement+ database connection pool
- JS daily question (12)
- Stack and queue and priority queue (large heap and small heap) simulation implementation and explanation of imitation function
- Understand activity workflow
- VirtualBox has expanded the capacity of virtual hard disk (without modifying the original data)
- How to install Office2010 installation package? How to install Office2010 installation package on computer
猜你喜欢

Understand activity workflow

后置通知的流程分析与功能实现有哪些内容你还记得吗?

那个准时上下班,从不愿意加班加点的人,在我前面升职了...

Activity workflow table structure learning

This article takes you to understand the implementation of surround notification @around and final notification @after
![[file download] easyexcel quick start](/img/fd/b3b08c67c5a81f0ab58c20653f9398.png)
[file download] easyexcel quick start

Arfoundation starts from scratch 3- create an arfoundation project

Quick start JDBC

Architecture analysis of three-tier project and parameter name injection of construction method

SparkSql批量插入或更新,保存数据到Mysql中
随机推荐
ODOO开发教程之透视表
AttributeError: ‘module‘ object has no attribute ‘create_connection‘
源码编译pytorch坑
ThreadPoolExecutor simple to use
How does WPS use smart fill to quickly fill data? WPS method of quickly filling data
Mysql多对多关系,分组拼接把多个数据查询到一条数据上
How does word view document modification traces? How word views document modification traces
JDBC statement + resultset introduction
电脑无法打开excel表格怎么办?excel打不开的解决方法
TCP three handshakes and four waves
SparkSql批量插入或更新,保存数据到Mysql中
SM integration is as simple as before, and the steps are clear (detailed)
NumPy基础
P5714 [deep foundation 3. Case 7] obesity
传奇开区网站如何添加流量统计代码
MySQL many to many relationship, grouping and splicing to query multiple data to one data
【微信小程序】swiper滑动页面,滑块左右各露出前后的一部分,露出一部分
On AspectJ framework
那个准时上下班,从不愿意加班加点的人,在我前面升职了...
Raspberry pie 4B + Intel neural computing stick (stick2) +yolov5 feasibility study report