首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从相应的TabView页面标题中填充SwipeView

从相应的TabView页面标题中填充SwipeView
EN

Stack Overflow用户
提问于 2017-07-03 09:34:07
回答 1查看 181关注 0票数 1

使用SwipeViewTabBar共同创建多个单独的可见页面,并且导航方便,这是一种严格的前向方法:

代码语言:javascript
复制
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])访问它的页面。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-07-03 09:45:42

快!太棒了!我很快就找到了答案:

代码语言:javascript
复制
Repeater {
    model: swipeView.count
    TabButton {
        text: swipeView.contentChildren[index].title
    }
}

甚至更简单

代码语言:javascript
复制
Repeater {
    model: swipeView.contentChildren
    TabButton {
        text: modelData.title
    }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44882207

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档