c++ - 属性QtObject marginHints:QtObject {…}

标签 c++ qml kde plasma

查看KDE等离体的来源,一些小部件声明了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.



将范围合并在一起,该项目的任何子组件的任何内部组件都可能使用过它。

关于c++ - 属性QtObject marginHints:QtObject {…},我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55128811/

相关文章:

c++ - 如何从另一个线程关闭对话框? Qt

c++ - 将 nullptr 传递给可变模板指针

qt - 如何强制加载程序重新加载/重置或删除预加载 qml 页面的缓存

c++ - QAbstractListModel::Data() 方法从未被调用

localization - KDE 中的错误/混合语言

c++ - osgDB/FileUtils在我的代码中导致编译器错误

c++ - 使用 CMake 从二进制文件编译和添加目标文件

c++ - 无法打开包含文件 "AIUtilities.h": No such file or directory. 但它存在?

qt - 如何在 QML 中向 StackLayout 添加过渡?

python - seaborn kde 图中的级别是什么意思?