QML SplitView:此控件如何将其子项目处理为内部项目?

QML SplitView: How this control handle their children items into internal item?

我查看了 SplitView 的源代码 (%QT_SOURCE_PATH%\qml\QtQuick\Controls\SplitView.qml) 并注意到它使用 3 个项目来操纵拆分器和项目:

Item {
    id: contents
    visible: false
    anchors.fill: parent
}
Item {
    id: splitterItems
    anchors.fill: parent
}
Item {
    id: splitterHandles
    anchors.fill: parent
}

根据代码,新项目通过函数 addItem_impl(项)。从函数 addItem_impl(item) 调用函数 addItem_impl(item) 传递 ID 为 [=22= 的 Item 中的每个子项]内容。但是我想知道 root item 中的所有子项是如何放入 contents Item?

通过 default property:

default property alias __contents: contents.data

来自documentation

An object definition can have a single default property. A default property is the property to which a value is assigned if an object is declared within another object's definition without declaring it as a value for a particular property.

[...]

You will notice that child objects can be added to any Item-based type without explicitly adding them to the children property. This is because the default property of Item is its data property, and any items added to this list for an Item are automatically added to its list of children.

Default properties can be useful for reassigning the children of an item. See the TabWidget Example, which uses a default property to automatically reassign children of the TabWidget as children of an inner ListView. See also Extending QML.