属性 QtObject marginHints: QtObject { ... }

property QtObject marginHints: QtObject { ... }

查看 KDE plasmoid 的来源,一些小部件声明 marginHints 属性 像 this:

    property QtObject marginHints: QtObject {
        property int left: Math.round(units.smallSpacing / 2)
        property int top: Math.round(units.smallSpacing / 2)
        property int right: Math.round(units.smallSpacing / 2)
        property int bottom: Math.round(units.smallSpacing / 2)
    }

虽然没有从任何地方明确引用,但删除它们实际上会破坏布局。

它是否在其他地方有记载?这是如何工作的?这是某种 QML 魔法吗?

看来,QML 的范围解析比我想象的要复杂得多。阅读文档(又名 RTFM)有帮助。

https://doc.qt.io/qt-5/qtqml-documents-scope.html

根据那篇文章:

Component Scope

Each QML component in a QML document defines a logical scope. Each document has at least one root component, but can also have other inline sub-components. The component scope is the union of the object ids within the component and the component's root object's properties.

[...]

Component Instance Hierarchy

In QML, component instances connect their component scopes together to form a scope hierarchy. Component instances can directly access the component scopes of their ancestors.

将作用域组合在一起,它可能已被该项目的任何子组件的任何内部组件使用。