【问题标题】:How to use QML StackView's status property?如何使用 QML StackView 的 status 属性?
【发布时间】:2017-12-21 14:19:46
【问题描述】:

我在 StackView QML 类型中有一些 3 个组件,我可以使用 push()pop() 更改视图。再往下,当我 push() 或 pop() 到那个 UI 时,我想根据用户配置更新 UI(Component)。通过文档,我发现Stack.status 在这种情况下很有趣,但不知道如何使用它。

谁能举个例子?

以下是我如何将屏幕加载到堆栈视图并导航的代码:

StackView {
    id: stackView
    visible: false
    //        rotation: 180
    anchors.fill: parent

    initialItem: componentHome

    Component.onCompleted:
    {

    }

}
Component
{
    id: componentHome
    Home
    {
        //This is how I traverse the screens
        onMenuClicked:
        {
            console.log("opening "+name+" screen")
            if(name === "settings")
            {
                //Here, for eg. how to update UI in Settings screen before pushing it?
                stackView.push(componentSettings)
            }
        }
    }
}
Component
{
    id: componentSettings
    Settings
    {
    }
}
Component
{
    id: componentPlay
    Play
    {
    }
}

【问题讨论】:

    标签: qt qml stackview


    【解决方案1】:

    我会这样做:

    import QtQuick.Controls 2.1
    
    StackView {
        id: stack
        anchors.fill: parent
        initialItem: page1
    }
    
    Button {
        text: "add page"
        onClicked: {
            var page = stack.push(page2, {color: "red"});
            //page.color = "red"; // - that also should work
        }
    }
    
    Component {
        id: page1
        Rectangle {
            color: "black"
        }
    }
    
    Component {
        id: page2
        Rectangle {
            color: "black"
        }
    }
    

    【讨论】:

      【解决方案2】:

      在组件中使用StackView.onStatusChanged: 应该对您有所帮助,但要小心 - 您无法定义您的组件是被弹出了还是被 StackView.status 推到了它上面(至少大约一年前是这样,我不能检查现在的情况)。一些细节你可以在my old question的小讨论中找到

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-05-29
        • 1970-01-01
        • 1970-01-01
        • 2017-01-31
        • 1970-01-01
        相关资源
        最近更新 更多