BlinCT
20 березня 2022 р. 01:51

Дополнить qml tab в существующий TabBar

Qt

Всем привет.
Возникла необходимость добавить один таб в TabBar который заполняется через Repeater.
Я пытаюсь добавить статичный один tab и уже после него Repeater должин остальные дополнять.
Через Repeater я добавляю остальыне tab потому что для разных обьектов и tab меняются. Но вот один в начале статичный мне теперь требуется добавить.
Ниже привожу код который за это отвечает

TabBar
    {
        id: tabBar

        width: parent.width
        anchors.top: comboBoxDevices.bottom

        background: Rectangle { color: "transparent" }

        Repeater {
            model: ObjectModel {
                id: tabsModel

                function reload(pages)
                {
                    tabsModel.clear()
                    for (var i = 0; i < pages.length; ++i)
                    {
                        tabsModel.append(tabButtonComponent.createObject(tabBar, {text: pages[i].title, stackLayoutIndex: pages[i].ObjectModel.index}))
                        if(pages[i].title!=="Advanced")
                            pages[i].reload()
                    }
                }
            }
        }

    }

    Component
    {
        id: tabButtonComponent

        TabButton
        {
            property int stackLayoutIndex: -1
//            width: implicitWidth
        }
    }

    StackLayout
    {
        width: parent.width
        currentIndex: tabsModel.count > 0 ? tabsModel.get(tabBar.currentIndex).stackLayoutIndex : 0
        anchors.top: tabBar.bottom
        anchors.left: parent.left
        anchors.right: parent.right
        anchors.bottom: parent.bottom
        Repeater
        {
            model: ObjectModel
            {
                id: pagesModel
                General { id: generalTab }
                Statistics { id: statisticsTab }
                Attributes { id: attributes }
                DeviceStat { id: deviceStat }
            }
        }
    }

Заранее благодарю.

1

Вам це подобається? Поділіться в соціальних мережах!

0

Коментарі

Only authorized users can post comments.
Please, Log in or Sign up