Qt 如何创建能够嵌套其他组件的组件

Qt 如何创建能够嵌套其他组件的组件,qt,qml,Qt,Qml,我想为其他组件创建带有标题和容器的框架。 它应该看起来像ColumnLayout。它嵌套其他组件并将它们排列在列中。 我需要在框架内通过代码动态重叠嵌套组件 我试试这个代码 ColumnLayout { id: root anchors.fill: parent TopRowButtons { id: topRowButtons height: root.height*0.15 } Item { id:

我想为其他组件创建带有标题和容器的框架。 它应该看起来像ColumnLayout。它嵌套其他组件并将它们排列在列中。 我需要在框架内通过代码动态重叠嵌套组件

我试试这个代码

ColumnLayout {
    id: root
    anchors.fill: parent

    TopRowButtons {
        id: topRowButtons
        height: root.height*0.15
    }

    Item {
        id: itemContaining
        Layout.fillHeight: true
        Layout.fillWidth: true
    }
}

但是,如果我将其他组件放入这些组件中,那么新组件将重叠到行按钮上。

您应该使用
default
关键字作为属性别名,该属性别名指向
ColumnLayout.data
属性,我认为您希望将其与
交换(因为您谈论的是重叠标题). 此外,如果您希望将
顶行按钮显示在内容上方,则它们应位于代码中较低的位置:

Item {
    id: root

    default property alias subdata : itemContainer.data

    ColumnLayout {
        id: itemContainer
        anchors.fill: parent
    }

    TopRowButtons {
        id: topRowButtons
        height: root.height*0.15
    }
}
数据
是外部
ColumnLayout
的默认属性,它接受任何对象,可视对象是
ColumnLayout
的父对象。如果只希望嵌套可视对象,还可以使用
子对象
属性