当前位置:网站首页>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 .
边栏推荐
猜你喜欢
365天挑战LeetCode1000题——Day 040 设计跳表 + 避免洪水泛滥 + 查找大小为 M 的最新分组 + 销售价值减少的颜色球
The latest tank battle 2022 full development notes-1
About realizing page Jump of website in Servlet
Mysql的自连接和联合查询
浅谈AspectJ框架
Xiaobai high salary shortcut Qt development game Snake
Getting started with solidity
C how to realize simple factory mode
SM整合原来这么简单,步骤清晰(详细)
ARFoundation从零开始5-AR图像跟踪
随机推荐
6.3 references
AUTOSAR从入门到精通100讲(七十八)-AUTOSAR-DEM模块
vs2019编译cryengine失败问题处理
Handwritten student management system
How to add a map to the legendary server
千人规模互联网公司研发效能成功之路
The latest tank battle 2022 - full development notes-3
关于servlet中实现网站的页面跳转
C语言用指向指针的指针对n个整数排序
小鲁客栈---预告篇
时间序列分析的表示学习时代来了?
京东云联合Forrester咨询发布混合云报告 云原生成为驱动产业发展新引擎
预约中,2022京东云产业融合新品发布会线上开启
ARFoundation从零开始8-Geospatial API(地理空间)开发
SM integration is as simple as before, and the steps are clear (detailed)
Soft link & hard link
数千个数据库、遍布全国的物理机,京东物流全量上云实录 | 卓越技术团队访谈录
Ros1 dead chicken data is stored in txt and SQLite
Qt版的贪食蛇游戏项目
Button for QT custom switch effect