简体   繁体   English

QML – 如何 go 返回上一页 (felgo)

[英]QML – how to go back to previous page (felgo)

I have an application with several pages.我有一个包含几页的应用程序。 One of them is a settings page where the user can select various settings.其中之一是设置页面,用户可以在其中 select 进行各种设置。 There are various buttons on the pages with which I can open the different pages.页面上有各种按钮,我可以使用它们打开不同的页面。

Currently I always switch between the pages with:目前我总是在页面之间切换:

page.navigationStack.push(nameOfPage) page.navigationStack.push(nameOfPage)

For most cases this is okay, but when I close the settingspage, I want to go back to the previous page (the page that was opened when I pressed the button to open settingspage) and not have to specify 1 page.在大多数情况下,这没关系,但是当我关闭设置页面时,我想 go 回到上一页(当我按下按钮打开设置页面时打开的页面)并且不必指定 1 页。

I am working with QML/Felgo我正在使用 QML/Felgo

code example: import Felgo 3.0 import QtQuick 2.0 import QtQuick.Controls 1.4代码示例:导入 Felgo 3.0 导入 QtQuick 2.0 导入 QtQuick.Controls 1.4

App {
    id: app
    NavigationStack {
        Page {
            id: page
            navigationBarHidden: true
            Text { text: qsTr("1st page") }
            Button {
                y: 30; text: "go to 2nd page"
                onClicked: page.navigationStack.push(secondpage)
            }
            Button {
                y: 60; text: "go to settings"
                onClicked: page.navigationStack.push(settingsPage)
            }
        }
    }

    Component {
        id: secondpage
        Page {
          navigationBarHidden: true
          Text { text: qsTr("2nd page") }
          Button {
              y: 30; text: "go to 1st page"
              onClicked: page.navigationStack.push(page)
          }
          Button {
              y: 60; text: "go to settings"
              onClicked: page.navigationStack.push(settingsPage)
          }
        }
    }

    Component {
        id: settingsPage
        Page {
            navigationBarHidden: true
            Text { text: qsTr("settings page") }
            //various settings
            Button {
                y: 30; text: "go to previous page"
                onClicked: page.navigationStack.push(page)  //??
            }
        }
    }
}

i dont know what to put for line 47 - so that I can get to either 1st or 2nd page - depending on where I opened settingspage from我不知道在第 47 行放什么 - 这样我就可以进入第一页或第二页 - 取决于我从哪里打开设置页面

any help would be really appreciated任何帮助将非常感激

I think you want to use this method:我想你想使用这种方法:

https://felgo.com/doc/felgo-navigationstack/#pop-method https://felgo.com/doc/felgo-navigationstack/#pop-method

This will perform the reverse animation (like hitting a back button in iOS or Android) and will remove and destroy the top Page on the stack.这将执行反向 animation(就像在 iOS 或 Android 中点击后退按钮),并将删除并销毁堆栈上的顶部页面。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM