State
配合使用:state、states、PropertyChanges。
Item 属性:state 当前状态,states 定义所有状态。
非 Item 对象通过 StateGroup 来使用 State。
Rectangle {
id: signal
width: 200; height: 200
state: "NORMAL"
states: [
State {
name: "NORMAL"
PropertyChanges { target: signal; color: "green"}
PropertyChanges { target: flag; state: "FLAG_DOWN"}
},
State {
name: "CRITICAL"
PropertyChanges { target: signal; color: "red"}
PropertyChanges { target: flag; state: "FLAG_UP"}
}
]
}
when 属性:
Rectangle {
id: bell
width: 75; height: 75
color: "yellow"
states: State {
name: "RINGING"
when: (signal.state == "CRITICAL")
PropertyChanges {target: speaker; play: "RING!"}
}
}
阅读全文 »