State(状态)组件是一组来自默认配置的批处理更改。所有项都有一个默认状态,该状态定义对象和属性值的默认配置。可以通过将State项添加到states属性来定义新的状态,以允许项在不同的配置之间切换。
State组件的基本用法如下:
Window {id: winwidth: 640height: 480visible: truetitle: qsTr("Hello World")Rectangle {id: rectanchors.fill: parentcolor: "steelblue"state: "initial"MouseArea {id: maanchors.fill: parenthoverEnabled: trueonClicked: {rect.state === 'clicked'? rect.state="":rect.state='clicked'}onEntered: {rect.state = "enter"}onExited: {rect.state = 'initial'}}states: [State {name: "initial"PropertyChanges {target: rectcolor: "steelblue"}},State {name: "clicked"PropertyChanges {target: rectcolor: "re"}},State {name: "enter"PropertyChanges {target: rectcolor: "green"}}]}
}