支持的HTML子集¶
描述文本小部件中对HTML标记的支持。
Qt的文本小部件能够显示富文本,使用HTML 4标记的子集进行指定。使用QTextDocument
的小部件,如QLabel和QTextEdit,能够以这种方式显示指定的富文本。
在文本小部件中使用HTML标记¶
小部件自动检测HTML标记并相应地显示富文本。例如,使用字符串"Hello Qt!"
设置标签的文本属性将导致标签显示如下文本:Hello Qt!
当HTML标记用于文本时,Qt遵循HTML 4规范定义的规则。这包括文本布局的默认属性,例如文本流的方向(从左到右),可以通过将dir
:ref:`
块属性¶
以下属性由 div
, dl
, dt
, h1
, h2
, h3
, h4
, h5
, h6
, p
标签支持:
align
(left
,right
,center
,justify
)
dir
(ltr
,rtl
)
列表属性¶
以下属性由 ol
和 ul
标签支持:
type
(1
,a
,A
,square
,disc
,circle
)
表格单元格属性¶
以下属性由td
和th
标签支持:
width
(绝对、相对或无值)
bgcolor
(Qtcolor names
或#RRGGBB
)
colspan
rowspan
align
(left
,right
,center
,justify
)
valign
(top
,middle
,bottom
)
CSS属性¶
下表列出了Qt的富文本引擎支持的CSS属性:
属性
值
描述
background-color
元素的背景颜色
background-image
元素的背景图片
color
文本前景色
font-family
字体家族名称
font-size
[ small | medium | large | x-large | xx-large ] |
pt | px 字体大小相对于文档字体,或以点或像素指定
font-style
[ 正常 | 斜体 | 倾斜 ]
font-weight
[ normal | bold | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 ]
text-decoration
none | [ underline || overline || line-through ]
额外的文本效果
font
[ [ <’font-style’> || <’font-weight’> ]? <’font-size’> <’font-family’> ]
字体简写属性
text-indent
px 首行文本缩进的像素值
white-space
normal | pre | nowrap | pre-wrap
声明如何处理HTML中的空白。
margin-top
px 段落顶部边距,单位为像素
margin-bottom
px 底部段落边距,单位为像素
margin-left
px 段落的左边距,单位为像素
margin-right
px 段落的右边距,单位为像素
padding-top
px 表格单元格顶部内边距,单位为像素
padding-bottom
px 表格单元格底部内边距,单位为像素
padding-left
px 表格单元格左侧内边距,单位为像素
padding-right
px 表格单元格右侧内边距,单位为像素
padding
px 一次性设置所有内边距属性的简写。
vertical-align
baseline | sub | super | middle | top | bottom
垂直文本对齐。仅在文本表格单元格中垂直对齐时,仅适用 middle、top 和 bottom。
border-collapse
collapse | separate
文本表格的边框合并模式。如果设置为collapse,将不会应用单元格间距。
border-color
文本表格和表格单元格的边框颜色。
border-top-color
表格单元格的顶部边框颜色。
border-bottom-color
表格单元格的底部边框颜色。
border-left-color
表格单元格的左边框颜色。
border-right-color
表格单元格的右边框颜色。
border-style
none | dotted | dashed | dot-dash | dot-dot-dash | solid | double | groove | ridge | inset | outset
文本表格和表格单元格的边框样式。
border-top-style
表格单元格的顶部边框样式。
border-bottom-style
表格单元格的底部边框样式。
border-left-style
表格单元格的左边框样式。
border-right-style
表格单元格的右边框样式。
border-width
px 表格或单元格边框的宽度
border-top-width
px 表格单元格的上边框宽度。
border-bottom-width
px 表格单元格的底部边框宽度。
border-left-width
px 表格单元格的左边框宽度。
border-right-width
px 表格单元格的右边框宽度。
border-top
px 设置上边框宽度、样式和颜色的简写
border-bottom
px 用于设置底部边框宽度、样式和颜色的简写
border-left
px 用于设置左边框宽度、样式和颜色的简写
border-right
px 设置右边框宽度、样式和颜色的简写
border-top
<width>px <border-style> <border-color>
设置上边框宽度、样式和颜色的简写
border-bottom
px 设置底部边框宽度、样式和颜色的简写
border
px 设置所有四个边框的宽度、样式和颜色的简写
background
[ <’background-color’> || <’background-image’> ]
背景简写属性
page-break-before
[ auto | always ]
使在段落/表格前强制分页成为可能
page-break-after
[ auto | always ]
使在段落/表格后强制分页成为可能
float
[ left | right | none ]
指定图像或文本在另一个元素中的位置。请注意,
float
属性仅支持表格和图像。
text-transform
[ uppercase | lowercase ]
选择在显示文本之前将执行的转换。
font-kerning
[ normal | none ]
启用或禁用文本字符之间的字距调整。
font-variant
small-caps
在显示文本之前执行小型大写字母转换。
word-spacing
px 指定每个单词之间的替代间距。
line-height
[% | px | pt | cm] 指定行的高度。它可以是以下之一:
以像素、点或厘米为单位的固定行高。
当前字体大小的百分比。
Qt特定的CSS属性¶
除了前面列出的标准CSS属性外,以下Qt特定的属性也可以用于样式化文本块:
属性
值
描述
-qt-block-indent
将文本块缩进指定的空格数。
-qt-list-indent
将列表项缩进指定的空格数。
-qt-list-number-prefix
将给定的字符串前缀添加到HTML有序列表的列表编号中。
-qt-list-number-suffix
将给定的字符串后缀到HTML有序列表中的列表编号。
-qt-paragraph-type
empty
隐藏文本块。
-qt-table-type
root | frame
root
渲染文本块为内联,没有边框和缩进,而frame
则在新行上渲染它们,并带有边框。
-qt-user-state
将其添加为文本块的用户数据。
支持的CSS选择器¶
所有CSS 2.1选择器类都支持,除了伪类选择器如:first-child
、:visited
和:hover
。