Jump to content

Qt Writing Guidelines

From Qt Wiki
(Redirected from QtWritingGuidelines)


The Qt Writing Guidelines contains information about writing Qt documentation in a consistent way. Though there are exceptions, maintain the consistency level outlined in the guidelines or the existing Qt documentation.

This guideline is maintained by the Qt Documentation Team, with members across the different Qt Group sites. Visit their page at: Contributing to Qt Documentation

Purpose and scope

This page is the short entry point for anyone who writes Qt documentation. It covers the decisions a writer makes first, and each section ends with a link to the detailed rules.

The Qt documentation is written in a source format that a tool called QDoc reads. QDoc turns documentation comments in C++ and QML source files, and separate .qdoc files, into the HTML pages on doc.qt.io. QML is the declarative language that Qt Quick applications use. A command that starts with a backslash, such as \brief, tells QDoc what a piece of text is.

To make your first documentation change, follow these steps in order: find the source file that holds the text, edit it, run QDoc and Vale on it, and push the change to Gerrit. The sections Checking your documentation and Contributing to Qt Documentation cover the last steps. Rules have IDs, such as R12 or G34. The letter R marks a rule that a tool checks using regular expressions, and G marks a rule that needs a person's judgment.

Start with the three habits that fix most problems: write in active voice, put the main point of each paragraph first, and write section titles in sentence case. The example shows the first habit.

Incorrect Correct
Events are ignored by the item when it is disabled. The item ignores events when it is disabled.

When two sources disagree, follow the one that ranks higher: this page first, then QUIP 25 (a Qt Project proposal document, here on documentation writing style), then the C++ Documentation Style and QML Documentation Style pages, then the Microsoft Writing Style Guide. The QDoc Manual is the authority for command syntax, not for style.

The full list of rules, each with a stable ID, is on the Qt Documentation Rules page. See Sources for the ranking of sources.

Choosing the content type

A content type is the kind of page or text that you write. The type decides which rules apply, because an API reference entry and a tutorial step read differently.

To choose the type, look at the QDoc command that opens the text. The main groups are:

  • API reference for C++ and QML, opened by commands such as \class, \fn, \qmltype, and \qmlproperty
  • Module pages, overviews, and concept pages, opened by \module, \qmlmodule, or \page
  • Examples, tutorials, and getting-started pages
  • Platform, deployment, porting, and tools pages
  • Commit messages and reports

The content-type table on the Rules page is the source of truth. It lists the detection pattern and the writing register of each type, and this page holds no second copy. A register is the way a type sounds: its person, tense, and sentence length. When a page fits no type, treat it as an overview page.

See the content type rules in Content types.

Language style

Say the text out loud. If it sounds weird, then it is weird...and may need editing.


Qt uses the Microsoft Writing Style Guide in the Qt documentation. Use clear and direct language in American English. We write to a diverse audience and we need to communicate Qt topics in an approachable and understandable manner.

Here are some specifics for Qt:

  1. Use active voice, not passive. Passive does not make a sentence formal, but unnecessarily weakens the sentence. See Verbs
  2. Use the pronoun you to address the reader when appropriate. See Nouns and Pronouns.
  3. Use because instead of since or as. See Use simple words, concise sentences.
  4. Use a serial comma, also known as the Oxford comma. See Commas.
  5. Use the correct spelling and case for Qt Products. See Qt Terms and Concepts.
  6. Be consistent with forming lists. The \list command starts a list, each item starts with \li, and \endlist closes it. Use the same tone or mode and be consistent about ending with periods.
  7. Use US spelling and avoid Latin abbreviations. See Use US spelling and avoid non-English words. For example, write that is instead of i.e., and for example instead of e.g..

The Substitutions and terminology section of the Rules page holds the full table of Latin terms and their replacements.

Translated documentation

New in Qt 6.8, the Qt Reference Documentation is available in translated formats. Choose words that are simpler to translate or interpret. If the text is too complicated, then it may be poorly translated by translation tools.

See the language rules in Tool-checkable rules and Judgment rules.

Titles and headings

Consistency is key...write sections in sentence-case, but maintain consistency with existing pages.

Write a section title as the argument to a \section1 or \section2 command. The \section1 command starts a top-level section of a page, and \section2 starts a subsection inside it.

Write section titles in sentence-case as indicated by the Microsoft Writing Style Guide. See Formatting titles.

The previous guideline about using title-case is no longer valid, but maintain consistency within the page for readability and neatness. The title of a page, set with the \title command, uses the same case as the other titles on that page.

A title names the topic. A reader who scans the table of contents should be able to predict what the section holds. Two checks help with a close call:

  • Prediction: a reader can say what the section holds without reading it.
  • Stability: the title is still correct after the status of the work changes.

A title is not a finding, a verdict, or a rhetorical question, and it carries no final period or colon. For example, Signals and slots names a topic, but Why signals are better than callbacks makes a claim.

Task-based titles

In Qt, the section title could be about performing tasks or a description of a sub-system.

Here are some suggestions:

  • For sections about performing tasks, use verbs in progressive form: Building..., Using..., Creating..., Connecting..., and so on.
  • For sections about a sub-system or a description, use nouns: Coordinate systems, Chart types, Dynamic properties, and so on.

Linking issues with section titles

Choose unique titles to avoid linking problems.

QDoc uses section titles as link targets, and a common issue is mis-linking to unwanted sections. This issue is because QDoc links to titles that already exist.

Search for already existing titles, run QDoc, and check the HTML output for missing or misdirected links.

See rule R12 and rule G31 in the Grammar and Judgment rules sections.

Paragraphs and sections

Say the point first, then stop.

A paragraph makes one point and states it in its first sentence. This sentence is the topic sentence. It is a plain statement of about 14 words, and never more than 30. The sentences after it give a reason, a condition, an example, or an exception.

Keep paragraphs to one to three sentences. Split a paragraph when it starts a second idea, and always when it passes about 100 words. End on the last supporting sentence, with no closing sentence that restates the point.

Introduce every list and table with one sentence that says what it shows. Keep a list to between two and seven items.

Incorrect Correct
This section looks at how the cache behaves. The answer may surprise you. The cache stores each result until the model changes.

Put one idea in each section, in the order what, why, and how. A section that needs a second idea becomes two sections.

See rule G34 in Judgment rules.

Writing API documentation with QDoc

Qt APIs are documented in the sources, and QDoc generates the HTML for the doc.qt.io site and an offline version for Qt Creator. These QDoc guidelines complement the QDoc Manual

C++ and QML documentation follow a similar style, but there are differences.

Visit the following pages to document APIs:

General syntax guidelines are on these pages:

The first thing to write for a class or a QML type is the brief: the one-sentence summary that the \brief command sets. QDoc shows it in lists of types and in the page description, and it ends with a period.

See the API markup rules in Tool-checkable rules.

Notes, warnings, and markup

Only noteworthy statements belong in a \note.

QDoc has a \note command that creates a stylized Note: in the documentation. Similarly, \warning creates a Warning:.

Use them sparingly but be aware of their intended use and consequences.

  • Notes and warnings break the flow of the paragraph or section, creating an aside or detour from the usual topic
  • \note is only for short statements. See \note command in the QDoc manual
  • Reserve \warning for critical information that leads to serious consequences

Think of the hierarchy of information. When several statements are important, put only the most important one in a \note.

The general hierarchy of information, in order of highlighted importance, is:

Statement → Advice → Note → Warning

Integrate the other statements into the paragraph. A one-line paragraph on its own is better than the overuse of notes.

Use a list if there are several notes after each other. For example, add \section1 Additional notes at the end of your page to collect the notes.

For example:

Additional notes

  • Statement A
  • Statement B
  • Statement C

Mark up text or code to indicate to the reader that the text is special...such as code or text visible to the application user.

These are the common markup commands in Qt documentation:

  • \c command for marking code such as default values or output. Rendered in monospace font.
  • \uicontrol command for UI text visible to application users. Rendered in bold.

See Text Markup for other markup commands

The comment below goes above the function in a C++ source file. The \fn command names the function, and \sa adds a see-also link. The comment generates the documentation for QWidget::focusNextChild():

/*!
    \fn bool QWidget::focusNextChild()

    Finds a new widget to give the keyboard focus to, as appropriate
    for \uicontrol Tab, and returns \c true if it can find a new widget, or
    false if it can't.

    \sa focusPreviousChild()
*/

See the markup rules in Judgment rules.

Examples, snippets, and images

Qt Examples are an important part of the Qt Framework. They show how the framework is to be used and inspire developers about possibilities with Qt. These pages help with creating, documenting, and how to contribute examples into the Qt repositories.

Make sure your snippet compiles and runs.

It is best to include code snippets using the \snippet <filename> command. Qt documentation aims to include compilable and usable code. If the code is inside a source file, then \snippet can quote it from overviews, tutorials, and API documentation.

Read the QDoc Manual about the other commands relating to including sources in documentation. See Including External Code

The previous guideline about using \code and \endcode is no longer preferred, though it is still possible to use these commands.

For quoting input or output text (from the terminal, for example), use the various quotation commands. See Including Code Inline

The requirements for images in Qt documentation are outlined in QUIP-21, Using images in Qt documentation.

You should add an alternate text (alt text) to images. The alt text fills the HTML's alt attribute for screen readers and accessibility tools. Start the text capitalized and do not end with a period.

\image imagename.webp {A window with a blue background}

See the alt text rules in Tool-checkable rules and Judgment rules.

Checking your documentation

Check your text before you push a change to Gerrit, the code review system of the Qt Project. These checks catch most problems early and make integration smoother.

Vale is a linter, a program that reads text and reports places that break a rule. It detects improper use of language and can make suggestions in-place. Vale has a command-line interface and is also available for Qt Creator and VS Code. For more information about Vale, visit Setting Up Vale.

Run QDoc on your change and read its warnings. The QDoc Manual explains how to run it. Then follow the checks in the list, starting with the regression test for a small edit:

An assisted review of documentation changes is planned. A pointer to it is added here when it is public.

See the checking rules in Enforcement levels.

See also