几何
每个元素都有四个几何属性 x、y、width 和 height,其类型为 length。 {#sls.geom.properties}
x 和 y 是从元素父元素左上角到元素左上角的偏移量。
width 和 height 是元素的大小,从该角向右和向下延伸。 {#sls.geom.relative}
根元素的 x 和 y 属性没有意义,不得使用。 {#sls.geom.window.root}
绑定根元素的 x 或 y 已废弃。
窗口大小可以通过 width 和 height 设置。
当 x 没有绑定时,它默认为 (parent.width - self.width) / 2,
y 默认为 (parent.height - self.height) / 2:
即沿该轴将元素在其父元素中居中的值。 {#sls.geom.default-position}
当 width 或 height 没有绑定时,默认值取决于元素类型:
Rectangle 的宽度或高度与其父元素相同。 {#sls.geom.default-size}
布局内的元素由布局定位和确定大小,而不是使用这些默认值。
在此示例中,两个矩形都覆盖整个窗口: {#sls.geom.example.intro}
export component Example inherits Window { Rectangle { background: #2a6e3f; Rectangle { } }}slint
求值为百分比的 width 或 height 绑定
相对于父元素的同名属性:
width: 50%; 是 width: parent.width * 50%; 的简写。
© 2026 SixtyFPS GmbH