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,譬如QLabelandQTextEdit,能够显示以此方式指定的富文本。
Widgets automatically detect HTML markup and display rich text accordingly. For example, setting a label’s
textproperty 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.
The following table lists the HTML tags supported by Qt’s rich text engine:
Tag
描述
Comment
a锚点或链接
支持
hrefandname属性。
addressAddress
bBold
bigLarger font
blockquoteIndented paragraph
bodyDocument body
支持
bgcolorattribute, which can be a Qtcolor name或#RRGGBBcolor specification.
brLine break
centerCentered paragraph
citeInline citation
如同
i.
codeCode
如同
tt.
ddDefinition data
dfnDefinition
如同
i.
divDocument division
支持标准 块属性 .
dlDefinition list
支持标准 块属性 .
dtDefinition term
支持标准 块属性 .
emEmphasized
如同
i.
fontFont size, family, and/or color
支持下列属性:
size,face,和color(Qtcolor namesor#RRGGBB).
h1Level 1 heading
支持标准 块属性 .
h2Level 2 heading
支持标准 块属性 .
h3Level 3 heading
支持标准 块属性 .
h4Level 4 heading
支持标准 块属性 .
h5Level 5 heading
支持标准 块属性 .
h6Level 6 heading
支持标准 块属性 .
head文档 Header 头
hrHorizontal line
支持
widthattribute, which can be specified as an absolute or relative (%) value.
htmlHTML 文档
iItalic
img图像
支持
src,source(for Qt 3 compatibility),width,和height属性。
kbdUser-entered text
metaMeta-information
If a text encoding is specified using the
metatag, it is picked up by . Likewise, if an encoding is specified totoHtml(), the encoding is stored using ametatag, for example:<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
liList item
nobrNon-breakable text
olOrdered list
支持标准 列表属性 .
pParagraph
Left-aligned by default. Supports the standard 块属性 .
prePreformated text
qtQt rich-text document
同义词为
html. Provided for compatibility with earlier versions of Qt.
sStrikethrough
sampSample code
如同
tt.
smallSmall font
spanGrouped elements
strongStrong
如同
b.
subSubscript
supSuperscript
tableTable
支持下列属性:
border,bgcolor(Qtcolor namesor#RRGGBB),cellspacing,cellpadding,width(absolute or relative), andheight.
tbody表本体
什么都不做。
td表数据单元格
支持标准 表单元格属性 .
tfootTable footer
什么都不做。
thTable header cell
支持标准 表单元格属性 .
theadTable header
若
theadtag is specified, it is used when printing tables that span multiple pages.
title文档标题
The value specified using the
titletag is available throughmetaInformation().
trTable row
支持
bgcolorattribute, which can be a Qtcolor name或#RRGGBBcolor specification.
ttTypewrite font
uUnderlined
ulUnordered list
支持标准 列表属性 .
varVariable
如同
i.
The following attributes are supported by the
div,dl,dt,h1,h2,h3,h4,h5,h6,ptags:
align(left,right,center,justify)
dir(ltr,rtl)
The following attribute is supported by the
olandultags:
type(1,a,A,square,disc,circle)
The following attributes are supported by the
tdandthtags:
width(absolute, relative, or no-value)
bgcolor(Qtcolor namesor#RRGGBB)
colspan
rowspan
align(left,right,center,justify)
valign(top,middle,bottom)
Besides the standard CSS properties listed earlier, the following Qt-specific properties can also be used to style a text block:
特性
值
描述
-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
emptyHides the text block.
-qt-table-type
root | frame
rootrenders the text blocks inline without borders and indentation, whereasframerenders them on a new line with a frame around.
-qt-user-state
<number>Adds it as user data for the text block.
All CSS 2.1 selector classes are supported except pseudo-class selectors such as
:first-child,:visitedand:hover.