Search code examples
c++qmlkde-plasma

property QtObject marginHints: QtObject { ... }


Looking at the sources of KDE plasmoids, some of widgets declare marginHints property like 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)
    }

While not explicitly referenced from anywhere, removing them actually breaks the layout.

Is it even documented elsewhere? How this works? Is this some kind of QML magic?


Solution

  • It appears, QML has much more complex scope resolution than I imagined. Reading the docs (aka RTFM) help though.

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

    According to that article:

    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.

    Combining scopes together, it might've been used by any inner component of any child component of that item.