参考:https://blog.csdn.net/cqltbe131421/article/details/83148918
这个是简单的应用。
原作者在github上放上了源码,能在实际中用,方便进行子界面切换:
地址:https://github.com/cedoduarte/QML_StackView_example
上代码:
main.qml文件:
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
ApplicationWindow {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
header: ToolBar {
RowLayout {
anchors.fill: parent
ToolButton {
text: qsTr("‹")
onClicked: mystackview.pop()
}
Label {
text: qsTr("Stackview Example App")
elide: Label.ElideRight
horizontalAlignment: Qt.AlignHCenter
verticalAlignment: Qt.AlignVCenter
Layout.fillWidth: true
}
}
}
StackView {
anchors {
left: parent.left
right: parent.right
bottom: parent.bottom
top: header.bottom
}
id: mystackview
initialItem: starting_page
}
Component {
id: starting_page
StartingPage {
}
}
Component {
id: second_page
SecondPage {
}
}
Component {
id: third_page