Qt QML StackView,如何在推送项中导航?
我的应用程序有一个stackview,它有两个QML文件。 我需要从一个QML文件导航到另一个QML文件,从QML文件本身内部导航到另一个QML文件,在这里我无法访问stackview来推送或弹出。 我应该如何设计这个 Main.qml 以下是两个QML文件: QMLfile1.qmlQt QML StackView,如何在推送项中导航?,qt,qml,stackview,Qt,Qml,Stackview,我的应用程序有一个stackview,它有两个QML文件。 我需要从一个QML文件导航到另一个QML文件,从QML文件本身内部导航到另一个QML文件,在这里我无法访问stackview来推送或弹出。 我应该如何设计这个 Main.qml 以下是两个QML文件: QMLfile1.qml 我有另一个与上面类似的QML文件。您有很多选择 一种方法是,向QMLfile1.qml的根元素添加一个信号,并在main.qml中连接到它。更改将在那里执行 您还可以将属性var回调添加到QMLfile1.qml
我有另一个与上面类似的QML文件。您有很多选择 一种方法是,向QMLfile1.qml的根元素添加一个信号,并在main.qml中连接到它。更改将在那里执行 您还可以将属性var回调添加到QMLfile1.qml的根元素中,在实例化StackView时在其中注入push方法
最后,您不能隐藏StackView的id并跨文件边界访问它。我通常不喜欢这样。请分享一些代码来激发我的想象力。你应该提供任何描述你的代码的源代码。你说我不能访问stackview是什么意思?很抱歉。我已经用代码更新了。我没有添加代码的原因是因为示例StackView代码是这样的。嗨,谢谢。你能给我一个示例代码吗?对不起,我现在时间不多。你能再概括一下你的计划用例吗?这将帮助我知道,哪个选项最适合你。。。如果有的话。这可能是非常好的,一个StackLayout或SwipeView可能更符合你的要求。谢谢:我知道怎么做了。我在拥有StackView的QML文件中创建了每个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:
}
}
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
}
}