在本页

表格和列表

使用这些命令可以创建列表和表格。列表作为单独段落左对齐显示。表格作为单独段落居中显示。表格的宽度取决于其内容的宽度。

\table

\table\endtable 命令会对表格内容进行分隔。

该命令接受一个参数,指定表格宽度占页面宽度的百分比:

/*!
   \table 100 %

      ...

   \endtable
*/

上述代码可确保表格填满所有可用空间。如果表格宽度小于 100%,生成的文档中表格将居中。

表格可以包含标题、行和列。行以 \row命令开始,由单元格组成,每个单元格以 \li命令开头。还有一种 \header命令,它是一种特殊格式的行。

/*!
   \table
   \header
       \li Qt Core Feature
       \li Brief Description
   \row
       \li \l {Signal and Slots}
       \li Signals and slots are used for communication
          between objects.
   \row
       \li \l {Layout Management}
       \li The Qt layout system provides a simple
          and powerful way of specifying the layout
          of child widgets.
   \row
       \li \l {Drag and Drop}
       \li Drag and drop provides a simple visual
          mechanism which users can use to transfer
          information between and within applications.
   \endtable
*/

您还可以让单元格跨几行几列。例如

/*!
   \table
   \header
       \li {3,1} This header cell spans three columns,
          but only one row.
   \row
       \li {2, 1} This table cell spans two columns,
          but only one row
       \li {1, 2} This table cell spans only one column,
       but two rows.
   \row
       \li A regular table cell
       \li A regular table cell
   \endtable
*/

另请参见 \header, \row\li.

\header 命令表示以下表格单元格是当前表格的列头。

该命令只能在\table... \endtable 命令中使用。一个标题可以包含多个单元格。使用\li命令创建单元格。

页眉单元格的文本在表格单元格中居中,并使用粗体字体显示。

/*!
   \table
   \header
       \li Qt Core Feature
       \li Brief Description
   \row
       \li \l {Signal and Slots}
       \li Signals and slots are used for communication
          between objects.
   \endtable
*/

另请参阅 \table, \row\li.

\row

\row 命令在表格中开始新的一行。属于新行的\li将紧跟在\row 项之后。

该命令只能在\table... \endtable 命令中使用。一行可以包含多个单元格。使用\li命令创建单元格。

每行的单元格背景颜色在两种灰色之间交替,使行与行之间更容易区分。单元格内容左对齐。

/*!
   \table
   \header
       \li Qt Core Feature
       \li Brief Description
   \row
       \li \l {Signal and Slots}
       \li Signals and slots are used for communication
          between objects.
   \row
       \li \l {Layout Management}
       \li The Qt layout system provides a simple
          and powerful way of specifying the layout
          of child widgets.
   \row
       \li \l {Drag and Drop}
       \li Drag and drop provides a simple visual
          mechanism which users can use to transfer
          information between and within applications.
   \endtable
*/

另请参见 \table, \header\li.

\value

\value 命令开始记录 C++ 枚举项。

该命令的第一个参数是值名。值名前面可以有一个用方括号括起来的可选的since子句。值描述位于值名称之后。说明在下一个空行或\value 处结束。参数以表格形式显示。

注: 要在\value 描述中包含图像,请使用 \inlineimage命令。

如果没有since子句,\value 命令可能如下所示:

\value QtInfoMsg A message generated by the qInfo() function.

带有since子句的同一命令则如下所示:

\value [since 5.5] QtInfoMsg A message generated by the qInfo() function.

文档将位于相关类、头文件或命名空间文档中。请参见 \enum文档中。

注: 自 Qt 5.4 起,\value 命令也可在主题之外使用。 \enum主题之外使用。在这种情况下,QDoc 会渲染一个两列表格,列出常量名称(从第一个参数中提取)及其描述。例如,可在 \qmlproperty主题中记录 QML 枚举属性的可接受值。

另请参阅 \enum\omitvalue.

\omitvalue

\omitvalue 命令将 C++ 枚举项排除在文档之外。

该命令的唯一强制性参数是将被省略的枚举项的名称。如果枚举项后面有单行描述,也会被省略。

请参阅 \enum文档中的示例。

另请参见 \enum\value\since

\list

\list\endlist 命令为项目列表定界。

使用 \li命令创建每个列表项。一个列表总是包含一个或多个项目。列表可以嵌套。例如

/*!
    \list
        \li Qt Reference Documentation: Getting Started
        \list
            \li How to Learn Qt
            \li Installation
            \list
                \li Qt/X11
                \li Qt/Windows
                \li Qt/Mac
                \li Qt/Embedded
            \endlist
        \li Tutorial and Examples
        \endlist
    \endlist
*/

\list 命令使用一个可选参数,为列表项提供其他外观。

/*!
   \list
       \li How to Learn Qt
       \li Installation
       \li Tutorial and Examples
   \endlist
*/

如果在\list 命令中提供 "A "作为参数,则子弹会按字母顺序替换为字符:

  1. 如何学习 Qt
  2. 安装
  3. 教程和示例

如果将 "A "替换为 "1",列表项将按升序编号:

  1. 如何学习 Qt
  2. 安装
  3. 教程和示例

如果将 "i "作为参数,则子弹会被罗马数字取代:

  1. 如何学习 Qt
  2. 安装
  3. 教程和示例

最后,如果你提供 "I "作为可选参数,就可以让列表项以罗马数字升序排列:

  1. 如何学习 Qt
  2. 安装
  3. 教程和示例

你也可以让列表从任何字符或数字开始,只需提供你想从哪个数字或字符开始即可。例如

/*!
   \list G
       \li How to Learn Qt
       \li Installation
       \li Tutorial and Examples
   \endlist
*/

另请参见 \li.

\li (表格单元格,列表项)

\li 命令用于标记表格单元格或列表项。该命令仅用于表格列表

在下一条\li 命令、下一条 \endtable, 或 \endlist命令。参见 \table\list为例。

如果在表格中使用该命令,还可以指定项目应跨几行或几列。

/*!
   \table
   \header
       \li {3,1} This header cell spans three columns
          but only one row.
   \row
       \li {2, 1} This table item spans two columns
          but only one row
       \li {1, 2} This table item spans only one column,
       but two rows.
   \row
       \li A regular table item
       \li A regular table item
   \endtable
*/

如果不指定,项目将跨一列和一行。

另请参阅 \table, \header\list.

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