QML:
动态创建对象
动态删除对象(不要试图手动删除由Repeater或者Loader创建的实例)
application.qml | SelfDestroyingRect.qml |
{
id: imageDisplay
width: 0; height: parent.height;
anchors.left: catalog.right;
visible: false;
states: [
State {
name: "display"; when: visiable===true;
PropertyChanges {
target: imageDisplay
width: root.width - catalog.width;
}
}
]
transitions: [
Transition {
SpringAnimation {
target: imageDisplay;
property: "width";
damping: 0.2;
spring: 2;
}
}
]
}
手工切换元素状态:
Rectangle {
id: root;
states: [
State {
name: "minSize"
PropertyChanges {
target: hideButtonLabel
text: ">"
}
PropertyChanges {
target: root
width: 10;
}
}
]
transitions: [
Transition {
NumberAnimation { target: root; property: "width"; duration: 200; easing.type: Easing.InOutQuad }
}
]
MouseArea {
anchors.fill: parent;
onClicked: {
if(root.state == '') {
root.state = "minSize"
} else {
root.state = ''
}
}
}
}