Supported HTML Subset¶
Describes the support for HTML markup in text widgets.
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: Hello Qt!
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
:ref:` <Supported-HTML-Subset>` attribute to blocks of text.
Block Attributes¶
The following attributes are supported by the div
, dl
, dt
, h1
, h2
, h3
, h4
, h5
, h6
, p
tags:
align
(left
,right
,center
,justify
)
dir
(ltr
,rtl
)
List Attributes¶
The following attribute is supported by the ol
and ul
tags:
type
(1
,a
,A
,square
,disc
,circle
)
Table Cell Attributes¶
The following attributes are supported by the td
and th
tags:
width
(absolute, relative, or no-value)
bgcolor
(Qtcolor names
or#RRGGBB
)
colspan
rowspan
align
(left
,right
,center
,justify
)
valign
(top
,middle
,bottom
)
CSS Properties¶
The following table lists the CSS properties supported by Qt’s rich text engine:
Qt-specific CSS properties¶
Besides the standard CSS properties listed earlier, the following Qt-specific properties can also be used to style a text block:
Property
Values
Description
-qt-block-indent
<number>
Indents the text block by the specified no. spaces.
-qt-list-indent
<number>
Indents the list items by the specified no. of spaces.
-qt-list-number-prefix
<string>
Prefixes the given string to list number in an HTML ordered list.
-qt-list-number-suffix
<string>
Suffixes the given string to list number in an HTML ordered list.
-qt-paragraph-type
empty
Hides the text block.
-qt-table-type
root | frame
root
renders the text blocks inline without borders and indentation, whereasframe
renders them on a new line with a frame around.
-qt-user-state
<number>
Adds it as user data for the text block.
Supported CSS Selectors¶
All CSS 2.1 selector classes are supported except pseudo-class selectors such as :first-child
, :visited
and :hover
.
© 2022 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.