QML Documentation Style

This page is part of the Qt Writing Guidelines.

Though there are exceptions, these guidelines should be followed. Keeping that in mind, at least be consistent within the page. Meaning, the class member documentation should have the same style.

QDoc can process QML types defined as C++ classes and QML types defined in .qml files. For C++ classes documented as QML types, the QDoc comments are in the .cpp file while QML types defined in QML are in the .qml file. The C++ classes must also be documented documented with the QML topic commands [doc-snapshot.qt-project.org]:

For QML types defined in .qml files, QDoc will parse the QML and determine the properties, signals, and the type within the QML definition. The QDoc
block then needs to be immediately above the declaration. For QML types implemented in C++, QDoc will output warnings if the C++ class documentation does not exist.

QML Module Versions

QDoc considers the version specified in the \qmlmodule command as the import statement. Types which belong to the module do not need to specify the version, only the module name.

  1.  /*!
  2.     \qmlmodule QtQuick.Controls 1.1
  3.     #this is the same as the import statement
  4.  
  5. */
  6.      
  7. /*!
  8.     \qmltype Button
  9.     \inqmlmodule QtQuick.Controls
  10.     #QDoc will associate this Button to whatever version QtQuick.Controls has. (only one version per release)
  11.  
  12. */

There are two versions important for the user to know: Qt version and QML module version.

Use

  • “\since 5.3” for \qmltype
  • “\since <qml module> <version>” for \qmlproperty and the members.

“\since QtQuick 2.3” in a property documentation block will generate: “This property was introduced in QtQuick 2.3”

QML Types

The \qmltype [doc-snapshot.qt-project.org] command is for QML type documentation.

  1.     \qmltype TextEdit
  2.     \instantiates QQuickTextEdit
  3.     \inqmlmodule QtQuick
  4.     \since 4.8
  5.     \ingroup qtquick-visual
  6.     \ingroup qtquick-input
  7.     \inherits Item
  8.     \brief Displays multiple lines of editable formatted text
  9.  
  10.     The TextEdit item displays a block of editable, formatted text.
  11.  
  12.     It can display both plain and rich text. For example:
  13.  
  14.     \qml
  15.         TextEdit {
  16.             width: 240
  17.             text: "<b>Hello</b> <i>World!</i>"
  18.             font.family: "Helvetica"
  19.             font.pointSize: 20
  20.             color: "blue"
  21.             focus: true
  22.         }
  23.     \endqml
  24.  
  25.     \image declarative-textedit.gif
  26.  
  27.     ... omitted detailed description
  28.  
  29.     \sa Text, TextInput, {examples/quick/text/textselection}{Text Selection example}

Some commonly used commands and context commands [doc-snapshot.qt-project.org]:

  • \brief [doc-snapshot.qt-project.org] – the brief description mandatory
  • \inqmlmodule [doc-snapshot.qt-project.org] mandatory
  • \instantiates [doc-snapshot.qt-project.org] – accepts the C++ class which implements the QML type as the argument. For types implemented in QML, this is not needed.
  • \since [doc-snapshot.qt-project.org] – Add the Qt version the type was introduced in. mandatory (see Note: below about backdating APIs)

Note: It was decided that we will not backdate APIs, so only add the \since with the version number of an upcoming release. See https://codereview.qt-project.org/#change,43797

The brief description provides a summary for the QML type. The brief does not need to be a complete sentence and may start with a verb. QDoc will append the brief description onto the QML type in tables and generated lists. Don’t forget the period at the end.

  1. \qmltype ColorAnimation
  2. \brief Animates changes in color values.

Here are some alternate verbs for the brief statement:

  • “Provides…”
  • “Specifies…”
  • “Describes…”

The detailed description follows the brief and may contain images, snippet, and link to other documentation.

Properties

The property description focuses on what the property does. Property documentation usually starts with “This property…” but for certain properties, these are the common expressions:

  • “This property holds…”
  • “This property describes…”
  • “This property represents…”
  • “Returns \c true when… and \c false when…” – for properties that are marked read-only.
  • “Sets the…” – for properties that configure a type.

Aliases

The QDoc parser cannot guess the type of the alias, therefore, the type must be fully documented with the \qmlproperty [doc-snapshot.qt-project.org] command.

Signals and Handlers Documentation

QML signals are documented either in the QML file or in the C++ implementation with the \qmlsignal [doc-snapshot.qt-project.org] command. Signal documentation must include the condition for emitting the signal, mention the corresponding signal handler, and document whether the signal accepts a parameter.

  1. /*
  2.     This signal is emitted when the user clicks the button. A click is defined
  3.     as a press followed by a release. The corresponding handler is
  4.     \c onClicked.
  5. */

These are the possible documentation styles for signals:

  • “This signal is triggered when…”
  • “Triggered when…”
  • “Emitted when…”

Methods and JavaScript Functions

Typically, function documentation immediately precedes the implementation of the function in the .cpp file. The topic command [doc-snapshot.qt-project.org] for functions is \qmlmethod [doc-snapshot.qt-project.org]. For functions in QML or JavaScript, the documentation must reside immediately above the function declaration.

The function documentation starts with a verb, indicating the operation the function performs.

  1. /*
  2.     \qmlmethod QtQuick2::ListModel::remove(int index, int count = 1)
  3.  
  4.     Deletes the content at \a index from the model.
  5.  
  6.     \sa clear()
  7. */
  8. void QQuickListModel::remove(QQmlV8Function *args)

Some common verbs for function documentation:

  • “Copies…” – for constructors
  • “Destroys…” – for destructors
  • “Returns…” – for accessor functions

The function documentation must document:

  • the return type
  • the parameters
  • the actions of the functions

The \a [doc-snapshot.qt-project.org] command marks the parameter in the documentation. The return type documentation should link to the type documentation or be marked with the \c [doc-snapshot.qt-project.org] command in the case of boolean values.

Enumerations

QML enumerations are documented as QML properties with the \qmlproperty [doc-snapshot.qt-project.org] command. The type of the property is enumeration.

  1. /*!
  2. \qmlproperty enumeration QtQuick2::Text::font.weight
  3.  
  4. Sets the font's weight.
  5.  
  6. The weight can be one of:
  7.  
  8. \list
  9. \li Font.Light
  10. \li Font.Normal - the default
  11. \li Font.DemiBold
  12. \li Font.Bold
  13. \li Font.Black
  14. \endlist
  15. */

The QDoc comment lists the values of the enumeration. If the enumeration is implemented in C++, the documentation may link to the corresponding C++ enumeration. However, the QDoc comment should advise that the enumeration is a C++ enumeration.