The Q3StyleSheet class is a collection of styles for rich text rendering and a generator of tags. 更多...
| 头: | #include <Q3StyleSheet> |
| 继承: | QObject |
| Q3StyleSheet (QObject * parent = 0, const char * name = 0) | |
| virtual | ~Q3StyleSheet () |
| virtual void | error (const QString & msg ) const |
| Q3StyleSheetItem * | item (const QString & name ) |
| const Q3StyleSheetItem * | item (const QString & name ) const |
| virtual void | scaleFont (QFont & font , int logicalSize ) const |
| QString | convertFromPlainText (const QString & plain , Q3StyleSheetItem::WhiteSpaceMode mode = Q3StyleSheetItem::WhiteSpacePre) |
| Q3StyleSheet * | defaultSheet () |
| QString | escape (const QString & plain ) |
| bool | mightBeRichText (const QString & text ) |
| void | setDefaultSheet (Q3StyleSheet * sheet ) |
The Q3StyleSheet class is a collection of styles for rich text rendering and a generator of tags.
By creating Q3StyleSheetItem objects for a style sheet you build a definition of a set of tags. This definition will be used by the internal rich text rendering system to parse and display text documents to which the style sheet applies. Rich text is normally visualized in a QTextEdit 或 QTextBrowser . However, QLabel , QWhatsThis and QMessageBox also support it, and other classes are likely to follow. With QSimpleRichText it is possible to use the rich text renderer for custom widgets as well.
默认 Q3StyleSheet object has the following style bindings, sorted by structuring bindings, anchors, character style bindings (i.e. inline styles), special elements such as horizontal lines or images, and other tags. In addition, rich text supports simple HTML tables.
The structuring tags are
| Structuring tags | 注意事项 |
|---|---|
<qt>
...
</qt>
|
A Qt rich text document. It understands the following attributes:
|
<h1>...</h1>
|
A top-level heading. |
<h2>...</h2>
|
A sublevel heading. |
<h3>...</h3>
|
A sub-sublevel heading. |
<p>...</p>
|
A left-aligned paragraph. Adjust the alignment with the
align
attribute. Possible values are
left
,
right
and
center
.
|
<center>...
<br>
</center>
|
A centered paragraph. |
<blockquote>...
<br>
</blockquote>
|
An indented paragraph that is useful for quotes. |
<ul>...</ul>
|
An unordered list. You can also pass a type argument to define the bullet style. The default is
type=disc
; other types are
circle
and
square
.
|
<ol>...</ol>
|
An ordered list. You can also pass a type argument to define the enumeration label style. The default is
type="1"
; other types are
"a"
and
"A"
.
|
<li>...</li>
|
A list item. This tag can be used only within the context of
<ol>
or
<ul>
.
|
<pre>...</pre>
|
For larger chunks of code. Whitespaces in the contents are preserved. For small bits of code use the inline-style
code
.
|
Anchors and links are done with a single tag:
| Anchor tags | 注意事项 |
|---|---|
<a>...</a>
|
An anchor or link.
|
The default character style bindings are
| Style tags | 注意事项 |
|---|---|
<em>...</em>
|
Emphasized. By default this is the same as
<i>...</i>
(italic).
|
<strong>...</strong>
|
Strong. By default this is the same as
<b>...</b>
(bold).
|
<i>...</i>
|
Italic font style. |
<b>...</b>
|
Bold font style. |
<u>...</u>
|
Underlined font style. |
<s>...</s>
|
Strike out font style. |
<big>...</big>
|
A larger font size. |
<small>...</small>
|
A smaller font size. |
<sub>...</sub>
|
Subscripted text |
<sup>...</sup>
|
Superscripted text |
<code>...</code>
|
Indicates code. By default this is the same as
<tt>...</tt>
(typewriter). For larger chunks of code use the block-tag
<
pre>
.
|
<tt>...</tt>
|
Typewriter font style. |
<font>...</font>
|
Customizes the font size, family and text color. The tag understands the following attributes:
|
Special elements are:
| Special tags | 注意事项 |
|---|---|
<img>
|
An image. The image name for the mime source factory is given in the source attribute, for example
<img src="qt.xpm">
The image tag also understands the attributes
width
and
height
that determine the size of the image. If the pixmap does not fit the specified size it will be scaled automatically (by using
QImage::smoothScale
()).
The
|
<hr>
|
A horizontal line. |
<br>
|
A line break. |
<nobr>...</nobr>
|
No break. Prevents word wrap. |
In addition, rich text supports simple HTML tables. A table consists of one or more rows each of which contains one or more cells. Cells are either data cells or header cells, depending on their content. Cells which span rows and columns are supported.
| Table tags | 注意事项 |
|---|---|
<table>...</table>
|
A table. Tables support the following attributes:
|
<tr>...</tr>
|
A table row. This is only valid within a
table
. Rows support the following attribute:
|
<th>...</th>
|
A table header cell. Similar to
td
, but defaults to center alignment and a bold font.
|
<td>...</td>
|
A table data cell. This is only valid within a
tr
. Cells support the following attributes:
|
Creates a style sheet called name ,采用父级 parent . Like any QObject it will be deleted when its parent is destroyed (if the child still exists).
By default the style sheet has the tag definitions defined above.
[虚拟]
Q3StyleSheet::
~Q3StyleSheet
()
Destroys the style sheet. All styles inserted into the style sheet will be deleted.
[static]
QString
Q3StyleSheet::
convertFromPlainText
(const
QString
&
plain
,
Q3StyleSheetItem::WhiteSpaceMode
mode
= Q3StyleSheetItem::WhiteSpacePre)
Auxiliary function. Converts the plain text string plain to a rich text formatted paragraph while preserving most of its look.
mode
defines the whitespace mode. Possible values are
Q3StyleSheetItem::WhiteSpacePre
(no wrapping, all whitespaces preserved) and
Q3StyleSheetItem::WhiteSpaceNormal
(wrapping, simplified whitespaces).
另请参阅 escape ().
[static]
Q3StyleSheet
* Q3StyleSheet::
defaultSheet
()
Returns the application-wide default style sheet. This style sheet is used by rich text rendering classes such as QSimpleRichText , QWhatsThis and QMessageBox to define the rendering style and available tags within rich text documents. It also serves as the initial style sheet for the more complex render widgets, QTextEdit and QTextBrowser .
另请参阅 setDefaultSheet ().
[虚拟]
void
Q3StyleSheet::
error
(const
QString
&
msg
) const
This virtual function is called when an error occurs when processing rich text. Reimplement it if you need to catch error messages.
Errors might occur if some rich text strings contain tags that are not understood by the stylesheet, if some tags are nested incorrectly, or if tags are not closed properly.
msg is the error message.
[static]
QString
Q3StyleSheet::
escape
(const
QString
&
plain
)
Auxiliary function. Converts the plain text string plain to a rich text formatted string with any HTML meta-characters escaped.
另请参阅 convertFromPlainText ().
Returns the style called name or 0 if there is no such style.
这是重载函数。
Returns the style called name or 0 if there is no such style (const version)
[static]
bool
Q3StyleSheet::
mightBeRichText
(const
QString
&
text
)
Returns true if the string text is likely to be rich text; otherwise returns false.
该函数使用快速,因此会简单试探。它主要校验第一换行符之前,是否存在看起来像标记的东西。尽管对于常见情况,结果可能是正确的,但不保证。
[虚拟]
void
Q3StyleSheet::
scaleFont
(
QFont
&
font
,
int
logicalSize
) const
Scales the font font to the appropriate physical point size corresponding to the logical font size logicalSize .
When calling this function, font has a point size corresponding to the logical font size 3.
Logical font sizes range from 1 to 7, with 1 being the smallest.
另请参阅 Q3StyleSheetItem::logicalFontSize (), Q3StyleSheetItem::logicalFontSizeStep (),和 QFont::setPointSize ().
[static]
void
Q3StyleSheet::
setDefaultSheet
(
Q3StyleSheet
*
sheet
)
Sets the application-wide default style sheet to sheet , deleting any style sheet previously set. The ownership is transferred to Q3StyleSheet .
另请参阅 defaultSheet ().