0

我正在创建一个应用程序,但 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 }
    }]
}
4

2 回答 2

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 }
于 2013-02-01T13:22:34.983 回答
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 }
    }]

}
于 2013-01-28T00:32:16.237 回答