Доступ к QML Stackview из файла, отличного от того, в котором он содержится - PullRequest
0 голосов
/ 08 февраля 2019

Я делаю приложение QML.Я определил main.qml, где я добавил StackView.Я загрузил страницу с этим «основным» стека, но из main.qml.Теперь мне нужно добавить что-то в это представление стека, но из другого файла (точнее, с одной из страниц, которые я ранее помещал в это представление стека).

Это то, что я сделал.

main.qml

ApplicationWindow {
    id: window
    visible: true
    width: 320
    height: 568
    title: qsTr("Stack")

    header: ToolBar {
        contentHeight: toolButton.implicitHeight

        ToolButton {
            id: toolButton
            text: stackView.depth > 1 ? "\u25C0" : ""
            font.pixelSize: Qt.application.font.pixelSize * 1.6
            onClicked: {
                if ( stackView.depth > 1 ) {
                    stackView.pop( )
                } else {
                    ...
                }


            }
        }

        Label {
            text: stackView.currentItem.title
            anchors.centerIn: parent
        }
    }


    StackView {
        id: stackView
        initialItem: "ListaInventarios.qml"
        anchors.fill: parent
    }


}

ListaInventarios.qml

Page {
    width: parent.width
    height: parent.height
    id: listaInventarios
    title: "Inventarios"


    ListView {
        id: lvInventarios
        anchors.fill: parent
        model: ListModel { ... }
        delegate: Component {
            Item {
                width: parent.width
                height: 40
                Column {
                    Text { text: nombreInventario; font.bold: true }
                    Text { text: fuenteDatos }
                }
                MouseArea {
                    anchors.fill: parent
                    onClicked: { lvInventarios.currentIndex = index }
                    onDoubleClicked: {

                    // HERE I NEED TO PUSH A NEW PAGE ON "stackView" (from main.qml)

                    }
                }
            }
        }

        highlight: Rectangle {
            color: "lightblue"
            radius: 5
        }

        focus: true

    }


    footer: ToolBar {
        id: barraInferior
        contentHeight: toolButton.implicitHeight
        Row {
            anchors {
                horizontalCenter: parent.horizontalCenter
                verticalCenter: parent.verticalCenter

            }

            ToolButton {
                text: "Nuevo"
                width: window.width / 2
                onClicked: {
                   ...
                }
            }

            ToolButton {
                text: "Borrar"
                width: window.width / 2
                onClicked: {
                    ...
                }

            }

        }
    }

}

1 Ответ

0 голосов
/ 08 февраля 2019

Используйте присоединенный StackView API :

onDoubleClicked: {
    listaInventarios.StackView.view.push("Foo.qml")
}

Обратите внимание, что вам необходимо добавить префикс вызова к элементу, который управляется StackView: listaInventarios.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...