CopperSpice API  1.9.2
Supported HTML Subset

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>CopperSpice</i>" will result in the label displaying text like this: Hello CopperSpice

When HTML markup is used for text, CopperSpice 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 the rich text engine.

TagDescriptionComment
a Anchor or link Supports the href and name attributes. The :visited selector is one which is not supported by the rich text engine. See supported-css-selectors for a list of others.
address Address
bBold
bigLarger font
blockquoteIndented paragraph
body Document body Supports the bgcolor attribute, which can be a CopperSpice color name or a #RRGGBB color specification.
brLine break
centerCentered paragraph
citeInline citationSame as i.
codeCodeSame as tt.
ddDefinition data
dfnDefinitionSame as i.
divDocument divisionSupports the standard block attributes.
dlDefinition listSupports the standard block attributes.
dtDefinition termSupports the standard block attributes.
emEmphasizedSame as i.
fontFont size, family, and/or color Supports the following attributes: size, face, and color (CopperSpice color names or #RRGGBB).
h1Level 1 headingSupports the standard block attributes.
h2Level 2 headingSupports the standard block attributes.
h3Level 3 headingSupports the standard block attributes.
h4Level 4 headingSupports the standard block attributes.
h5Level 5 headingSupports the standard block attributes.
h6Level 6 headingSupports the standard block attributes.
headDocument header
hr Horizontal lineSupports the width attribute, which can be specified as an absolute or relative (%) value.
htmlHTML document
iItalic
img ImageSupports the src, width, and height attributes.
kbdUser-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.
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP" />
liList item
nobrNon-breakable text
olOrdered listSupports the standard list attributes.
pParagraphLeft-aligned by default. Supports the standard block attributes.
prePreformatted text
sStrikethrough
sampSample codeSame as tt.
smallSmall font
spanGrouped elements
strongStrongSame as b.
styleStyle sheetAllows styling information to be included with the rich text. A CSS Properties limited subset of CSS syntax can be used to change the appearance of the text.
subSubscript
supSuperscript
tableTable Supports the following attributes: border, bgcolor (CopperSpice color names or #RRGGBB), cellspacing, cellpadding, width (absolute or relative), and height.
tbodyTable bodyDoes nothing.
tdTable data cellSupports the standard table cell attributes.
tfootTable footerDoes nothing.
thTable header cellSupports the standard table cell attributes.
thead Table headerIf the thead tag is specified, it is used when printing tables that span multiple pages.
title Document title The value specified using the title tag is available through QTextDocument::metaInformation().
tr Table row Supports the bgcolor attribute, which can be a CopperSpice color name or a #RRGGBB color specification.
ttTypewrite font
uUnderlined
ulUnordered listSupports the standard list attributes.
varVariableSame as i.

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 (CopperSpice color 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 the rich text engine.

PropertyValuesDescription
background-color<color>Background color for elements
background-image<uri>Background image for elements
color<color>Text foreground color
font-family<family name>Font family name
font-size[ small | medium | large | x-large | xx-large ] | <size>pt | <size>pxFont size relative to the document font, or specified in points or pixels
font-style[ normal | italic | oblique ]
font-weight[ normal | bold | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 ]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.
text-decorationnone | [ underline || overline || line-through ]Additional text effects
font[ [ <'font-style'> || <'font-weight'> ]? <'font-size'> <'font-family'> ]Font shorthand property
text-indent<length>pxFirst line text indentation in pixels
white-spacenormal | pre | nowrap | pre-wrapDeclares how whitespace in HTML is handled.
margin-top<length>pxTop paragraph margin in pixels
margin-bottom<length>pxBottom paragraph margin in pixels
margin-left<length>pxLeft paragraph margin in pixels
margin-right<length>pxRight paragraph margin in pixels
padding-top<length>pxTop table cell padding in pixels
padding-bottom<length>pxBottom table cell padding in pixels
padding-left<length>pxLeft table cell padding in pixels
padding-right<length>pxRight table cell padding in pixels
padding<length>pxShorthand for setting all the padding properties at once.
vertical-alignbaseline | sub | super | middle | top | bottomVertical text alignment. For vertical alignment in text table cells only middle, top, and bottom apply.
border-color<color>Border color for text tables.
border-stylenone | dotted | dashed | dot-dash | dot-dot-dash | solid | double | groove | ridge | inset | outsetBorder style for text tables.
background[ <'background-color'> || <'background-image'> ]Background shorthand property
page-break-before[ auto | always ]Make it possible to enforce a page break before the paragraph/table
page-break-after[ auto | always ]Make it possible to enforce a page break after the paragraph/table
float[ left | right | none ]Specifies where an image or a text will be placed in another element. The float property is only supported for tables and images.
text-transform[ uppercase | lowercase ]Select the transformation that will be performed on the text prior to displaying it.
font-variantsmall-capsPerform the smallcaps transformation on the text prior to displaying it.
word-spacing<width>pxSpecifies an alternate spacing between each word.

Supported CSS Selectors

All CSS 2.1 selector classes are supported except pseudo-class selectors such as :first-child, :visited and :hover.