将约束转换为锚点
在 Figma 中,约束描述了图层相对于其父级的位置。这些约束对应于 QML 中使用 X 和 Y 坐标实现的锚点、边距或固定定位。
锚点通过将锚点(top、bottom、left、right、fill、horizontal center、vertical center 或 baseline)与另一个 QML 组件关联,将该组件定位在另一个组件旁边或内部。
Figma 约束与 QML 并非所有属性都完全一致。例如,QML 中没有 scale 属性。
使用锚点进行定位时,插件会利用图层约束按以下方式设置相应 QML 组件的位置:
- 左侧或顶部:距离父组件左侧或顶部边缘指定边距的距离处。
- 右侧和底部:距离父级右侧或底部边缘指定边距的距离处。
- 左侧和右侧或顶部和底部:距离父级两个边缘的距离由 margin 属性指定,因此该组件会随父级一起伸缩。
- 居中:在父元素内水平和垂直方向均居中。
- 缩放:保持位置不变,并按父容器比例调整大小。
将约束转换为锚点和边距:
- 在插件中,进入“
”(Settings )>“Code ”。
在插件的“设置”页面中,通过“代码设置”中的锚点定位功能进行设置。
- 启用“Position with anchors ”。
- 选择“
”(Preview )以查看结果。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.