Qt 选项卡栏和选项卡按钮

Qt 选项卡栏和选项卡按钮,qt,qml,Qt,Qml,我想创建选项卡。因此,我使用选项卡栏和选项卡按钮创建选项卡,使用堆栈布局加载屏幕 注意:我不想使用加载器。仅使用堆栈布局如何加载屏幕。 请建议我怎么做 Item { id:screenTabs property var tabname : [qsTr("Tab1"),qsTr("Tab2"),qsTr("Tab3"),qsTr("Tab4"),qsTr("Tab5")]

我想创建选项卡。因此,我使用选项卡栏和选项卡按钮创建选项卡,使用堆栈布局加载屏幕

注意:我不想使用加载器。仅使用堆栈布局如何加载屏幕。 请建议我怎么做

Item {
    id:screenTabs

    property var tabname     :  [qsTr("Tab1"),qsTr("Tab2"),qsTr("Tab3"),qsTr("Tab4"),qsTr("Tab5")]
    property var tabScreen   :  ["qrc:/Tabscreen1.qml","qrc:/Tabscreen2.qml","qrc:/Tabscreen3.qml","qrc:/Tabscreen4.qml","qrc:/Tabscreen5.qml"]

    width                    :  parent.width
    height                   :  parent.height

    TabBar
    {
        id: bar
        width: parent.width*0.95
        anchors {
            top: parent.top
            topMargin: 15
            left: parent.left
            leftMargin: 10
        }

        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
            Loader
            {
                width: parent.width
                height: parent.height
                source: tabScreen[index]
            }
        }
    }
}
同样,在不使用loader的情况下,我按照如下所示的方式进行操作,但这并不是我所期望的:

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

        Item {

        }

        Item {


        }

        Item {

        }

        Item {

        }

        Item {

        }

    }

如果您不想使用加载器,我认为您必须实例化给定名称(而不是URI)的组件,并将它们放入第二个解决方案中提到的
容器
类型(这里是
堆栈布局

在不使用loader的情况下,我按照下图所示的方式进行操作,但这并不是我所期望的

为什么这不是你所期望的?您是否用您的组件更换了
项目
?如果出现导入错误,可能必须为组件添加
import
语句

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

    Tabscreen1 {}
    Tabscreen2 {}
    Tabscreen3 {}
    Tabscreen4 {}
    Tabscreen5 {}
}