状态和过度
2016-06-07 22:50
441 查看
假如有一些属性,我要改掉它,以后要还原回去,最方便的就是状态机,不需要保存原始的状态,把状态清空就恢复到原始了
一个例子,点击查看设置myparent的状态为do,do的属性是 width:0;height:0;opacity:0
设置状态或还原状态后会触发过度效果Transition color变色延时500 和opacity,x,contentY,height,width延时500
需要注意的是state的可见域,多测试几次就会了
一个例子,点击查看设置myparent的状态为do,do的属性是 width:0;height:0;opacity:0
设置状态或还原状态后会触发过度效果Transition color变色延时500 和opacity,x,contentY,height,width延时500
需要注意的是state的可见域,多测试几次就会了
Rectangle { antialiasing: true; clip: true; state: 'do' width: parent.width height: 400; id: myparent; color: "#ffffff" Column{ width: parent.width; spacing: 5; Button{ text:"关闭" onClicked: { myparent.state = "do"; } } Repeater{ model: 10; Rectangle{ width: parent.width; height: 80 color: "#5d91d9" border.width: 2; border.color: "blue"; Text{ text:"HELLO"; anchors.centerIn: parent } } } } states: [ State { name: "do" PropertyChanges {target: myparent; width:0;height:0;opacity:0} PropertyChanges {target: look; width:look.parent.width;height:80;opacity:1;color:"#c0a933";} } ] transitions: Transition { // Make the state changes smooth ParallelAnimation { NumberAnimation { duration: 500; properties: "opacity,x,contentY,height,width" } ColorAnimation { property: "color"; duration: 500 } } } } Rectangle{ id:look // visible: myparent.state=='do'?true:false anchors.top: root.top opacity: 0 width: 0; height: 0; color: "#000000" border.width: 1; radius: 5 border.color: Qt.lighter(color) Text { id: tttt; text: "查看"; anchors.centerIn: parent; } MouseArea{ anchors.fill: parent; onClicked: { myparent.state = myparent.state=="do"?"":"do" look.state = myparent.state; console.log(myparent.state) } } }
相关文章推荐
- Leetcode Isomorphic Strings
- 手机开发实战95——MMS介绍2
- Mybatis实体类和表映射
- python声明源文件编码格式、选择解释器
- apt-get
- [sh]函数+条件表达式
- 手机开发实战94——MMS介绍1
- 实现段前自动缩行的代码
- Apache Flink fault tolerance源码剖析(五)
- 自己写bootloader之问题:链接时出现undefined reference to '__umodsi3'
- JDBC 模糊查询 传参
- 手机开发实战93——PUSH介绍3
- 玩转Android之Drawable的使用
- 粗浅看 JNDI原理
- 玩转Android之Drawable的使用
- 玩转Android之Drawable的使用
- javascript中闭包的真正作用
- 玩转Android之Drawable的使用
- Spring框架的学习理解
- 内核加载错误module license