Qt Writing Guidelines: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
 
(20 intermediate revisions by the same user not shown)
Line 23: Line 23:
|+
|+
!Use
!Use
!Instead of
!Do not use
|-
|-
|that is
|'''''that is'''''
|i.e.
|i.e.
|-
|-
|for example
|'''''for example'''''
|e.g.
|e.g.
|-
|-
|and so on.
|'''''and so on.'''''
|etc.
|etc.
|-
|-
|through, using
|'''''through, using'''''
|via
|via
|-
|'''''advice, warning'''''
|caveat
|}
|}


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


== Using QDoc to write Qt documentation ==
== Writing API documentation with QDoc ==
These '''QDoc''' guidelines complement the [http://doc.qt.io/qt-5/qdoc-index.html QDoc Manual]
We document Qt APIs in the sources and use '''QDoc''' to generate the HTML for the doc.qt.io site and an offline version for Qt Creator.  These QDoc guidelines complement the [http://doc.qt.io/qt-5/qdoc-index.html QDoc Manual]


* [[QDoc Style Guidelines]] - proper use of commands, code blocks, markup, and indentation
'''C++ and QML documentation follow a similar style''', but there are differences.
 
Visit the following pages for documenting APIs
 
* [[C++ Documentation Style]]
* [[QML Documentation Style]]
General syntax related guidelines
* [[QDoc Linking Guidelines]]
* [[QDoc Linking Guidelines]]
* [[QDoc Project Templates]]
* [[QDoc Project Templates]]


== Writing API documentation ==
== Quoting code using snippets ==
We document Qt APIs in the sources and use '''QDoc''' to generate the HTML for the doc.qt.io site and an offline version for Qt Creator.
'''''Make sure your snippet compiles and runs.'''''


C++ and QML documentation follow a similar style, but there are differences. See the following pages for documenting APIs.
It is best to include code snippets using the '''\snippet <filename>''' command. We are striving to include compilable and usable code in the Qt documentation. If the code is inside a source file, then we can quote the code from overviews, tutorials, and API documentation.  


* [https://doc.qt.io/qt-6/qtwritingstyle-cpp.html C++ Documentation Style]
Read the ''QDoc Manual'' about the other commands relating to including sources in documentation. See [https://doc.qt.io/qt-6/07-0-qdoc-commands-includingexternalcode.html Including External Code]
* [https://doc.qt.io/qt-6/qtwritingstyle-qml.html QML Documentation Style]
 
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 [https://doc.qt.io/qt-6/06-qdoc-commands-includecodeinline.html Including Code Inline]


For designing Qt APIs, visit:
== Using markup for code and UI texts ==
'''''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.''


* [[API Design Principles]]
These are the common markup commands in Qt documentation:


== Quoting and marking code ==
* [https://doc.qt.io/qt-6/04-qdoc-commands-textmarkup.html#c-code-font \c] command for marking code such as default values or output. Rendered in monospace font.
'''''Make sure your snippet compiles and runs.'''''
* [https://doc.qt.io/qt-6/04-qdoc-commands-textmarkup.html#uicontrol \uicontrol] command for UI text visible to application users. Rendered in bold.


It is best to include code snippets using the '''\snippet <filename>''' command. We are striving to include compilable and usable code in the Qt documentation. If the code is inside a source file, then we can quote the code from overviews, tutorials, and API documentation.  
See [https://doc.qt.io/qt-6/04-qdoc-commands-textmarkup.html Text Markup] for other markup commands


Read the ''QDoc Manual'' about the other commands relating to including sources in documentation. See [https://doc.qt.io/qt-6/07-0-qdoc-commands-includingexternalcode.html Including External Code]
The code below generates the documentation for [https://doc.qt.io/qt-6/qwidget.html#focusNextChild QWidget::focusNextChild()]:<syntaxhighlight lang="c++">
/*!
    \fn bool QWidget::focusNextChild()


Markup with the '''\c''' command is beneficial to state that text is an input or output. See [https://doc.qt.io/qt-6/04-qdoc-commands-textmarkup.html Text Markup]
    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.


The previous guideline about using '''''\code''''' '''''and''' '''\endcode''' '''is no longer preferred''''', though it is still possible to use these commands.
    \sa focusPreviousChild()
*/


For quoting input or output text (from the terminal, for example), use the various quotation commands. See [https://doc.qt.io/qt-6/06-qdoc-commands-includecodeinline.html Including Code Inline]
</syntaxhighlight>


== Writing section titles ==
== Writing section titles ==
Line 104: Line 122:
Use them sparingly but be aware of their intended use and consequences.  
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.
* 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 [https://doc.qt.io/qt-6/11-qdoc-commands-specialcontent.html#note \note command] in the QDoc manual.
* '''''\note is only for short statements'''.'' See [https://doc.qt.io/qt-6/11-qdoc-commands-specialcontent.html#note \note command] in the QDoc manual
* Reserve '''\warning''' for critical information that lead to serious consequences.
* Reserve '''''\warning''''' for critical information that lead to serious consequences
Think of the hierarchy of information. When highlighting several important content, only have the most important statement in a \note. Notes that are not critical may not be that important.  
Think of the hierarchy of information. When highlighting several important content, only have the most important statement in a \note. Notes that are not critical may not be that important.  
'''''The general hierachy of information, in order of highlighted importance, is:'''''
'''''Statement'' → ''Advice'' → ''Note'' → ''Warning'''''


Instead, integrate the note into a paragraph. A one-line paragraph dangling in a page is better than the overuse of notes.
Instead, integrate the note into a paragraph. A one-line paragraph dangling in a page 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.   
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:  <blockquote>'''Additional notes:''' 
 
* Statement A
* Statement B
* Statement C
</blockquote>  


== Documenting examples ==
== Documenting examples ==
Line 126: Line 155:
* [https://contribute.qt-project.org/quips/21 QUIP-21] ''Using images in Qt documentation''
* [https://contribute.qt-project.org/quips/21 QUIP-21] ''Using images in Qt documentation''


== Linting with Vale ==
==Linting with Vale==
Vale is a linter that detects improper use of language and can make suggestions in-place. Vale has  command-line interface and is also available for Qt Creator and VS Code.
Vale is a linter that detects improper use of language and can make suggestions in-place. Vale has  command-line interface and is also available for Qt Creator and VS Code.



Latest revision as of 11:32, 16 December 2024

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

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. Essentially, 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 in 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 (\list). 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. Here is a summary :
Use Do not use
that is i.e.
for example e.g.
and so on. etc.
through, using via
advice, warning caveat

Translated Documentation

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

Writing API documentation with QDoc

We document Qt APIs in the sources and use QDoc to generate 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 for documenting APIs

General syntax related guidelines

Quoting code using snippets

Make sure your snippet compiles and runs.

It is best to include code snippets using the \snippet <filename> command. We are striving to include compilable and usable code in the Qt documentation. If the code is inside a source file, then we can quote the code 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

Using markup for code and UI texts

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 code below 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()
*/

Writing section titles

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

Section titles are written as arguments to \section1 and \section2 commands.

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.

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.

Using QDoc \note and \warning

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 lead to serious consequences

Think of the hierarchy of information. When highlighting several important content, only have the most important statement in a \note. Notes that are not critical may not be that important.

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

StatementAdviceNoteWarning

Instead, integrate the note into a paragraph. A one-line paragraph dangling in a page 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

Documenting examples

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.

Including images

The requirements for images in Qt documentation is outlined in QUIP-21.

  • QUIP-21 Using images in Qt documentation

Linting with Vale

Vale is a linter that detects improper use of language and can make suggestions in-place. Vale has command-line interface and is also available for Qt Creator and VS Code.

For more information about Vale, visit Setting Up Vale.

Testing and submitting documentation

Before pushing a change into codereview.qt-project.io, go over the following guidelines. These guidelines help with smoother documentation integration.

See also

QDoc changes should pass the QDocRegressionTesting