【发布时间】:2017-07-25 15:45:12
【问题描述】:
我是 QMl 的初学者,在 QT C++ 中的 StackWidget 上工作得更多。在 QML 中,我对使用 stackView 感到困惑,并编写了以下代码:
Window {
visible: true
width: 640
height: 480
title: qsTr("Stack view")
MainForm {
StackView {
id: stackView
x: 0
y: 0
width: 360
height: 360
initialItem: page1
Rectangle {
id: page1
//anchors.fill: parent
color: "lightgreen"
Button {
id: buttonPage1
text: "back to 2"
anchors.centerIn: parent
onClicked: {
stackView.pop() //**Is THIS CORRECT**
stackView.push(page2) //**Is THIS CORRECT**
}
}
TextEdit {
id: te1
width: 105
height: 40
text: "enter"
}
}
Rectangle {
id: page2
//anchors.fill: parent
color: "lightblue"
Button {
id: buttonPage2
text: "back to 1"
anchors.centerIn: parent
onClicked: {
stackView.pop() //**Is THIS CORRECT**
}
}
TextEdit {
id: te2
width: 109
height: 29
text: "enter"
}
}
}
}
}
以下是问题:
在 StackWidget 中,我使用 setCurrentIndex 设置所需的页面,我知道在 QML 中我应该使用 push 和 pop。在这种情况下,如何根据一些选择使用 push 和 pop 在 page1 和 page2 之间导航。 ?
最初,我可以将所有页面加载到 stackView 吗?
当我从stackView中弹出一个项目时,如何保存页面中的内容?
【问题讨论】:
-
听起来你想要StackLayout而不是StackView。
标签: qt qml qtquick2 qt-quick qtquickcontrols