查看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/