0

我的应用程序有一个包含两个 QML 文件的 stackview。而且我需要从一个 QML 文件导航到另一个 QML 文件内部,我将无法访问 stackview 来推送或弹出。我应该如何设计这个?

主.qml

Rectangle
{
   id: mainBkg
   color: "white"
   width: Screen.width
   height: Screen.height

    //Tickes every globalTimer.interval
    property int globalTick: 0


     Statusbar
     {
        width: Screen.width
        height: Screen.height*0.2
        id: statusBar
        Rectangle
        {
         width: parent.width
         height: parent.height*0.2
         anchors.fill: parent
         color: "green"

         Text {
            id: t
            text: qsTr("QMLfile1")

         }
       } 
     }//end of statusbar

    StackView {
        id: stackView
        anchors.top: statusBar.bottom
        anchors.centerIn: parent

        //What should be here? So that stackView
        //will be available inside the loaded items.   
        initialItem: 
    } 
}

以下是两个 QML 文件:

QMLfile1.qml

Rectangle
{
    width: parent.width
    height: parent.height*0.2

    anchors.fill: parent
    color: "green"


    Text {
        id: t
        text: qsTr("QMLfile1")

    }
    MouseArea:{
      onClicked: //move to other QML file in stackview
    }
}

我有另一个像上面那样的 QML 文件。

4

1 回答 1

1

你有很多选择。

一种是,将 a 添加signal到 的 -root元素中QMLfile1.qml,并在main.qml. 更改将在那里执行。

您还可以property var callback在实例化时添加 -注入- 方法的 -root元素。QMLfile1.qmlpushStackView

最后,您可以不隐藏idStackView跨文件边界访问它。我一般不喜欢这样。

于 2017-11-09T15:46:14.520 回答