使用SwipeView和TabBar共同创建多个单独的可见页面,并且导航方便,这是一种严格的前向方法:
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Layouts 1.3
Page {
id: page
header: TabBar {
id: tabBar
currentIndex: swipeView.currentIndex
TabButton {
text: qsTr("Page1")
}
TabButton {
text: qsTr("Page2")
}
}
SwipeView {
id: swipeView
width: page.width
height: page.height
currentIndex: tabBar.currentIndex
Page {
width: swipeView.width
height: swipeView.height
title: qsTr("Page1")
Pane {
anchors.fill: parent
}
}
Page {
width: swipeView.width
height: swipeView.height
title: qsTr("Page2")
Pane {
anchors.fill: parent
}
}
}
}title组件中有Page属性。在上述情况下,它是不可见的,但是在我的脑海中存储标签标题是合适的。我可以使用Repeater页面的一些属性(即.title)来生成TabBar的内容(例如,使用.title)来填充TabButton.text吗?
我查看了文档,但是找不到SwipeView的一个属性,它允许我通过索引(例如pages[index])访问它的页面。
发布于 2017-07-03 09:45:42
快!太棒了!我很快就找到了答案:
Repeater {
model: swipeView.count
TabButton {
text: swipeView.contentChildren[index].title
}
}甚至更简单
Repeater {
model: swipeView.contentChildren
TabButton {
text: modelData.title
}
}https://stackoverflow.com/questions/44882207
复制相似问题