我正在创建一个应用程序但是qml中的状态没有改变....这里LoginView
是一个QML文件而MessageView
也是一个QML文件我想将QML文件改为页面申请......我做错了什么,但我无法弄清楚是什么......请帮帮我
import QtQuick 1.0
Item {
id: main
LoginView {
id: login
anchors.fill: parent
visible: true
onLoginClicked: main.state="messageView"
}
MessageView {
id: message
anchors.fill: parent
visible: false
}
states: [State {
name:"messsageView"
PropertyChanges { target: login; visible: false }
PropertyChanges { target: message; visible: true }
},State {
name:""
PropertyChanges { target: message; visible: false }
PropertyChanges { target: login; visible: true }
}]
}
答案 0 :(得分:2)
LoginView {
id: login
anchors.fill: parent
visible: true
onLoginClicked: main.state="messageView" //state name is "messageView"
}
并且,次要期待:
states: [State {
name:"messsageView" // TRIPLE "s"
PropertyChanges { target: login; opacity: 0 }
答案 1 :(得分:0)
当某些“事件”发生时,不应发生变化。像这样:
import QtQuick 1.0
Rectangle
{
id: main
color: "blue"
width : 200
height: 200
Rectangle
{
id: login
color: "red"
anchors.fill: parent
opacity: 1
}
Rectangle {
id: message
color: "green"
anchors.fill: parent
opacity: 0
}
// --------------------------- THIS! ---------------------
MouseArea
{
anchors.fill: parent
onClicked: parent.state = "messsageView"
}
// -------------------------------------------------------
states: [State {
name:"messsageView"
PropertyChanges { target: login; opacity: 0 }
PropertyChanges { target: message; opacity: 1 }
},State {
name:""
PropertyChanges { target: message; opacity: 0 }
PropertyChanges { target: login; opacity: 1 }
}]
}