从相应 SwipeView 的 Pages 标题填充 TabView
Fill TabView from Pages' titles of corresponding SwipeView
创建多个独立可见页面并易于导航的简单方法是同时使用 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
}
}
}
}
Page
组件中有title
属性。在上面的例子中它是不可见的,但它是我脑海中存储选项卡标题的合适位置。我可以使用 SwipeView
页面(即 .title
)的某些属性生成(例如,使用 Repeater
)TabBar
的内容来填充 TabButton.text
吗?
我查看了文档,但找不到 SwipeView
的 属性,这使我可以通过索引(例如 pages[index]
)访问其页面。
Qt Quick 太棒了!我很快就找到了答案:
Repeater {
model: swipeView.count
TabButton {
text: swipeView.contentChildren[index].title
}
}
甚至更简单
Repeater {
model: swipeView.contentChildren
TabButton {
text: modelData.title
}
}
创建多个独立可见页面并易于导航的简单方法是同时使用 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
}
}
}
}
Page
组件中有title
属性。在上面的例子中它是不可见的,但它是我脑海中存储选项卡标题的合适位置。我可以使用 SwipeView
页面(即 .title
)的某些属性生成(例如,使用 Repeater
)TabBar
的内容来填充 TabButton.text
吗?
我查看了文档,但找不到 SwipeView
的 属性,这使我可以通过索引(例如 pages[index]
)访问其页面。
Qt Quick 太棒了!我很快就找到了答案:
Repeater {
model: swipeView.count
TabButton {
text: swipeView.contentChildren[index].title
}
}
甚至更简单
Repeater {
model: swipeView.contentChildren
TabButton {
text: modelData.title
}
}