簡體   English   中英

具有屬性的QML StackView推送組件

[英]QML StackView push component with properties

在QML StackView 文檔中 ,提到可以使用以下屬性推送item
stackView.push({item: someItem, properties: {fgcolor: "red", bgcolor: "blue"}})

有什么方法可以推動具有屬性的component 對於我的應用程序的不同視圖,我的組件基本上是其他.qml文件的包裝,例如:

Component{
    id: loginComponent
    Login{}//The Login.qml file of my project
}

這是我正在嘗試的:
Main.qml

    ApplicationWindow {
    id: appWindow
    visible: true
    width: Screen.desktopAvailableWidth
    height: Screen.desktopAvailableHeight
    property alias stackv: stackv
    property alias loginComponent: loginCom
        StackView {
        id: stackv
        anchors.top: topHeader.bottom
        anchors.topMargin: 10
        anchors.bottom: parent.bottom
        width: parent.width
        focus: true
            Component {
            id: loginCom
            Login {
                anchors.fill: parent
            }
        }
    }
    }

在另一個QML文件中,該文件已作為組件推送到stackview中,我正在按鈕的onClick方法之一上嘗試此操作:

onClicked: {
            appWindow.stackv.push({item: appWindow.loginComponent})
        }

我被彈出此錯誤:

QML StackView:推送:無需推送

如果我在沒有item屬性的情況下嘗試此操作,它將起作用。 但是,無論哪種方式,我都無法推送屬性。

您鏈接到文檔中 ,第一句話說:

推送到StackView上的項目可以是Item,URL,包含URL的字符串或Component。

因此,只需傳遞一個組件:

stackView.push({item: loginComponent, properties: {/*...*/}})

編輯:事實證明,在您編輯問題並添加警告輸出之后,您實際上是在Qt Quick Controls 2中使用StackView,而不是從文檔鏈接指向的Qt Quick Controls 1中使用StackView。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM