Qt's text widgets are able to display rich text, specified using a subset of HTML 4 markup. Widgets that use QTextDocument, such as QLabel and QTextEdit, are able to display rich text specified in this way.
Using HTML Markup in Text Widgets
Widgets automatically detect HTML markup and display rich text accordingly. For example, setting a label's text property with the string "<b>Hello</b> <i>Qt!</i>" will result in the label displaying text like this: HelloQt!
When HTML markup is used for text, Qt follows the rules defined by the HTML 4 specification. This includes default properties for text layout, such as the direction of the text flow (left-to-right) which can be changed by applying the dir attribute to blocks of text.
Supported Tags
The following table lists the HTML tags supported by Qt's rich text engine:
Tag
Description
Comment
a
Anchor or link
Supports the href and name attributes. Note that the :visited selector is one of those that is not supported by the rich text engine. See below for a list of others.
address
Address
b
Bold
big
Larger font
blockquote
Indented paragraph
body
Document body
Supports the bgcolor attribute, which can be a Qt color name or a #RRGGBB color specification.
Supports the width attribute, which can be specified as an absolute or relative (%) value.
html
HTML document
i
Italic
img
Image
Supports the src, source (for Qt 3 compatibility), width, and height attributes.
kbd
User-entered text
meta
Meta-information
If a text encoding is specified using the meta tag, it is picked up by Qt::codecForHtml(). Likewise, if an encoding is specified to QTextDocument::toHtml(), the encoding is stored using a meta tag, for example:
Specifies the font weight used for text, where normal and bold are mapped to the corresponding QFont weights. Numeric values are 8 times the equivalent QFont weight values.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter
ou par MP !