本页内容

向转换后的代码添加注释

开发

Figma to Qt 可将 Figma 图层转换为 QML 代码。若要向阅读转换后代码的开发人员传递备注,您可以在 Figma 中对图层添加注释。Figma to Qt 会将“Development ”类别中的注释转换为 QML 代码中的注释。

该注释会显示在Figma to Qt 根据该图层生成的QML代码上方。

为图层添加注释

若要为Figma to Qt 从图层生成的代码添加注释:

  1. 在 Figma 中,选择一个图层。
  2. 向该图层添加注释,并将类别设置为“Development ”。
  3. 在注释文本中输入备注内容。

当您转换设计时,Figma to Qt 会将该备注作为注释添加在 QML 代码上方。例如,在矩形上添加一条文本为“Shown while the data loads ”的注释,生成的结果如下:

// Shown while the data loads
Rectangle {
    // ...
}

向一个图层添加多个注释

您可以在同一图层上添加多个Development 注释。Figma to Qt 会将它们合并为一条注释,按您添加的顺序排列,并用空行分隔。

注意: Figma to Qt 仅转换“Development ”注释。它会忽略其他类别的注释、无类别的注释以及没有文本的注释。

关闭注释功能

Figma to Qt 默认会将Development 类别中的注释转换为评论。若要转换设计而不添加评论:

  1. 转到“设置 ”(Settings )>“Code ”。
  2. 清除“Export annotations ”。

    在插件的“设置”页面中,通过“代码”设置导出注释。

该设置仅影响注释。无论该设置如何,组件描述和文档链接都会自动转为评论。

为组件编写文档

Figma 中的组件及其变体带有描述,并可链接到外部文档。Figma to Qt 会将描述和文档链接作为注释添加到生成的 QML 文件顶部,位于来自组件本身注释的任何注释之前。

例如,一个描述为A themed button 的组件会生成:

import QtQuick

// A themed button
Rectangle {
    // ...
}

Figma to Qt 该功能使用描述的纯文本内容,因此 Figma 中的任何文本格式都不会被保留。每个文档链接都独占一行,并与描述之间以空行分隔。跨多行或长度超过 100 个字符的注释将显示为块注释。

注释变体

Figma to Qt 将变体转换为具有状态的组件,每个变体对应一个状态。变体内部图层上的注释将变为对应状态的注释,因此该注释会始终与所描述的变体保持关联。

另请参阅 “下载转换后的设计”和“预览转换后的设计”。

© 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.