Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Qt 在qml中为其创建选项卡和加载屏幕_Qt_Qml_Tabbar - Fatal编程技术网

Qt 在qml中为其创建选项卡和加载屏幕

Qt 在qml中为其创建选项卡和加载屏幕,qt,qml,tabbar,Qt,Qml,Tabbar,我试图创建一个选项卡,然后加载相应的屏幕,但当我试图在选项卡屏幕内放置一些组件时,无法实现这一点。这怎么可能 下面是创建的选项卡的代码段。 需要关于如何为每个选项卡动态创建相应屏幕的建议 Rectangle { width: Screen.width height: Screen.height property variant tabname: ["tab1","tab2","tab3"] property variant tabScreen: ["Sc

我试图创建一个选项卡,然后加载相应的屏幕,但当我试图在选项卡屏幕内放置一些组件时,无法实现这一点。这怎么可能

下面是创建的选项卡的代码段。 需要关于如何为每个选项卡动态创建相应屏幕的建议

    Rectangle
{
    width: Screen.width
    height: Screen.height

    property variant tabname: ["tab1","tab2","tab3"]
    property variant tabScreen: ["Screen1","Screen2", "Screen3"]

    function setTabName(name)
    {
        tabname = name
    }

    function setTabScreen(screen)
    {
        tabScreen = screen
    }

    TabBar
    {
        id: bar
        width: parent.width

        Repeater
        {
            model: tabname.length
            TabButton
            {
                text: tabname[index]
            }
        }
    }

    StackLayout
    {
        id: stacklyt
        width: parent.width
        height: parent.height
        currentIndex: bar.currentIndex
        anchors.top: bar.bottom

        Repeater
        {
            model: tabScreen.length
            Rectangle
            {
                id: tabRect
                color: "gray"
                Layout.preferredWidth: 10
                Layout.preferredHeight: 20

                Text {
                    id: name
                    text: tabScreen[index]
                    anchors.centerIn: parent
                }
            }
        }
    }


    Component.onCompleted:
    {
        setTabName(tabname)
        setTabScreen(tabScreen)
    }

}

id
属性添加到
Rectangle
,无论您在哪里引用
tabName
tabScreen
都使用此
id

Rectangle
{
    id: rect
    ...
    property variant tabName: ["tab1","tab2","tab3"]
    property variant tabScreen: ["Screen1","Screen2", "Screen3"]

    TabBar
    {
        ...
        Repeater
        {
            model: rect.tabName
            TabButton
            {
                text: rect.tabName[index]
            }
        }
    }

    StackLayout
    {
        ...

        Repeater
        {
            model: rect.tabScreen
            Rectangle
            {
                ...

                Text {
                    id: name
                    text: rect.tabScreen[index]
                    anchors.centerIn: parent
                }
            }
        }
    }
}
其次,属性
model
应该是正确的集合,而不是集合的长度(请参见代码)。另外,
setTabName
setTabScreen
功能是什么?就我理解你的问题而言,你不需要他们来达到你的目标