当前位置:网站首页>QML type: state state
QML type: state state
2022-07-29 05:23:00 【Shangguan Hongzhu】
Qml type :State state
Let's write a state converter .
1、 Define a state
The definition of a state can be declared as states: State { ... }
, It can also be declared as :states: [ State { ... } ]
Two forms .
Multiple states can be declared in the following form :
states: [
State { ... }, // state 1
State { ... }, // state 2
...
]
Declaration of multiple states , In fact, it declares something like an array ,[
and ]
Directly put in the array elements , This form can also be used when declaring a state , That is, the array element is a .
2、 Status name
For each state State
, We need to give him a unique name ( String type ).
3、 Bind target
For each state State
, You need to define one or more PropertyChanges
.
PropertyChanges
Need one target
, Used to bind a qml
object . For example, the following example :
states: State {
name: "resized"; when: mouseArea.pressed
PropertyChanges {
target: rect;
color: "blue";
height: container.height
}
}
Aforementioned color
、height
Are all rect
Properties of (rect
It's a Rectangle
Type of id
).
When switching to the current state , Will trigger PropertyChanges
Of the target control in color
、height
The change of ( Color turns blue 、 The height becomes consistent with the height of the container ).
4、 Trigger state change
There are two ways to trigger a state change :
One is : stay
State
One of themwhen
, The current state is triggered when this event occurs . As mentioned abovewhen: mouseArea.pressed
, Trigger when clicking and pressing .The other is : Active change in definition
states
Of controlsstate
attribute , This attribute inItem
In the definition of , So as long as the control type inherits fromItem
All of them have this attribute .This is the way . stay
onExited
、onPressed
Take the initiative to changerootRect.state
Value , Trigger the switching of the state , And then changerootRect
Ofopacity
attribute .Rectangle{ id: rootRect color: "transparent" state: "normal" MouseArea { onExited: { rootRect.state = "normal" } onPressed: { rootRect.state = "pressed" } } states: [ State { name: "normal" PropertyChanges{ target: rootRect; opacity: 0.6 } }, State { name: "pressed" PropertyChanges{ target: rootRect; opacity: 1 } } ] }
The complete implementation can search official account through wechat :“ Shangguan Hongzhu ”, Or scan the QR code below , Pay attention to and reply to :“State”, Get resource links . If you have any questions, you can also leave a message in official account .
边栏推荐
猜你喜欢
Unity3d - the object is too far away to see
MySQL many to many relationship, grouping and splicing to query multiple data to one data
京东云分布式链路追踪在金融场景的最佳实践
Mysql多对多关系,分组拼接把多个数据查询到一条数据上
研发效能生态完整图谱&DevOps工具选型必看
AUTOSAR from introduction to proficiency 100 lectures (78) -autosar-dem module
QT series - Installation
Scikit learn -- steps and understanding of machine learning application development
容器安全开源检测工具--问脉 VeinMind(镜像后门、恶意样本、敏感信息、弱口令等)
2022年泰迪杯数据挖掘挑战赛C题方案及赛后总结
随机推荐
osgSimplegl3结合RenderDoc工具
Deadlock analysis using jstack, jconsole, and jvisualvm
Getting started with solidity
时间序列分析的表示学习时代来了?
【[第一次写博客]Uda课程中的P控制器实现说明】
一文带你搞懂环绕通知@Around与最终通知@After的实现
[from_bilibili_DR_CAN][【Advanced控制理论】9_状态观测器设计][学习记录]
QT学习:使用JSON/XML等非ts文件实现多语言国际化
SQL log
Open source Huizhi creates the future | the openeuler sub forum of 2022 open atom global open source summit was successfully held
小白高薪捷径-Qt开发游戏—贪吃蛇
QML定制TabBar
6.2 function-parameters
365天挑战LeetCode1000题——Day 038 公交站间的距离 + 基于时间的键值存储 + 转变数组后最接近目标值的数组和 + 有界数组中指定下标处的最大值
数千个数据库、遍布全国的物理机,京东物流全量上云实录 | 卓越技术团队访谈录
CMake 设置vs启动运行环境路径
Qml类型:MouseArea
ARFoundation从零开始5-AR图像跟踪
Adb常用命令列表
365天挑战LeetCode1000题——Day 036 二叉树剪枝 + 子数组和排序后的区间和 + 删除最短的子数组使剩余数组有序