Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

  • Qt 4.8
  • Qt3SupportLight
  • Q3StyleSheet

Q3StyleSheet Class

TheQ3StyleSheet class is a collection of styles for rich text rendering and a generator of tags.More...

Header:#include <Q3StyleSheet>
Inherits:QObject

Public Functions

Q3StyleSheet(QObject * parent = 0, const char * name = 0)
virtual~Q3StyleSheet()
virtual voiderror(const QString & msg) const
Q3StyleSheetItem *item(const QString & name)
const Q3StyleSheetItem *item(const QString & name) const
virtual voidscaleFont(QFont & font, int logicalSize) const
  • 29 public functions inherited fromQObject

Static Public Members

QStringconvertFromPlainText(const QString & plain, Q3StyleSheetItem::WhiteSpaceMode mode = Q3StyleSheetItem::WhiteSpacePre)
Q3StyleSheet *defaultSheet()
QStringescape(const QString & plain)
boolmightBeRichText(const QString & text)
voidsetDefaultSheet(Q3StyleSheet * sheet)
  • 7 static public members inherited fromQObject

Additional Inherited Members

  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 1 signal inherited fromQObject
  • 8 protected functions inherited fromQObject

Detailed Description

TheQ3StyleSheet class is a collection of styles for rich text rendering and a generator of tags.

By creatingQ3StyleSheetItem 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 aQTextEdit or aQTextBrowser. However,QLabel,QWhatsThis andQMessageBox also support it, and other classes are likely to follow. WithQSimpleRichText it is possible to use the rich text renderer for custom widgets as well.

The defaultQ3StyleSheet 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 tagsNotes
<qt>...</qt>A Qt rich text document. It understands the following attributes:
  • title -- The caption of the document. This attribute is easily accessible withQTextEdit::documentTitle().
  • type -- The type of the document. The default type ispage. It indicates that the document is displayed in a page of its own. Another style isdetail, which can be used to explain certain expressions in more detail in a few sentences. Fordetail,QTextBrowser will then keep the current page and display the new document in a small popup similar toQWhatsThis. Note that links will not work in documents with<qt type="detail">...</qt>.
  • bgcolor -- The background color, for examplebgcolor="yellow" orbgcolor="#0000FF".
  • background -- The background pixmap, for examplebackground="granite.xpm". The pixmap name will be resolved by a Q3MimeSourceFactory().
  • text -- The default text color, for exampletext="red".
  • link -- The link color, for examplelink="green".
<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 thealign attribute. Possible values areleft,right andcenter.
<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 istype=disc; other types arecircle andsquare.
<ol>...</ol>An ordered list. You can also pass a type argument to define the enumeration label style. The default istype="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-stylecode.

Anchors and links are done with a single tag:

Anchor tagsNotes
<a>...</a>An anchor or link.
  • A link is created by using anhref attribute, for example <br><a href="target.qml">Link Text</a>. Links to targets within a document are achieved in the same way as for HTML, e.g. <br><a href="target.qml#subtitle">Link Text</a>.
  • A target is created by using aname attribute, for example <br><a name="subtitle"><h2>Sub Title</h2></a>.

The default character style bindings are

Style tagsNotes
<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:
  • color -- The text color, for examplecolor="red" orcolor="#FF0000".
  • size -- The logical size of the font. Logical sizes 1 to 7 are supported. The value may either be absolute (for example,size=3) or relative (size=-2). In the latter case the sizes are simply added.
  • face -- The family of the font, for exampleface=times.

Special elements are:

Special tagsNotes
<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 attributeswidth andheight that determine the size of the image. If the pixmap does not fit the specified size it will be scaled automatically (by usingQImage::smoothScale()).

Thealign attribute determines where the image is placed. By default, an image is placed inline just like a normal character. Specifyleft orright to place the image at the respective side.

<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 tagsNotes
<table>...</table>A table. Tables support the following attributes:
  • bgcolor -- The background color.
  • width -- The table width. This is either an absolute pixel width or a relative percentage of the table's width, for examplewidth=80%.
  • border -- The width of the table border. The default is 0 (= no border).
  • cellspacing -- Additional space around the table cells. The default is 2.
  • cellpadding -- Additional space around the contents of table cells. The default is 1.
<tr>...</tr>A table row. This is only valid within atable. Rows support the following attribute:
  • bgcolor -- The background color.
<th>...</th>A table header cell. Similar totd, but defaults to center alignment and a bold font.
<td>...</td>A table data cell. This is only valid within atr. Cells support the following attributes:
  • bgcolor -- The background color.
  • width -- The cell width. This is either an absolute pixel width or a relative percentage of table's width, for examplewidth=50%.
  • colspan -- Specifies how many columns this cell spans. The default is 1.
  • rowspan -- Specifies how many rows this cell spans. The default is 1.
  • align --Qt::Alignment; possible values areleft,right, andcenter. The default isleft.
  • valign --Qt::Vertical alignment; possible values aretop,middle, andbottom. The default ismiddle.

Member Function Documentation

Q3StyleSheet::Q3StyleSheet(QObject * parent = 0, constchar * name = 0)

Creates a style sheet calledname, with parentparent. Like anyQObject 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.

[virtual]Q3StyleSheet::~Q3StyleSheet()

Destroys the style sheet. All styles inserted into the style sheet will be deleted.

[static]QString Q3StyleSheet::convertFromPlainText(constQString & plain,Q3StyleSheetItem::WhiteSpaceMode mode = Q3StyleSheetItem::WhiteSpacePre)

Auxiliary function. Converts the plain text stringplain to a rich text formatted paragraph while preserving most of its look.

mode defines the whitespace mode. Possible values areQ3StyleSheetItem::WhiteSpacePre (no wrapping, all whitespaces preserved) andQ3StyleSheetItem::WhiteSpaceNormal (wrapping, simplified whitespaces).

See alsoescape().

[static]Q3StyleSheet * Q3StyleSheet::defaultSheet()

Returns the application-wide default style sheet. This style sheet is used by rich text rendering classes such asQSimpleRichText,QWhatsThis andQMessageBox 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 andQTextBrowser.

See alsosetDefaultSheet().

[virtual]void Q3StyleSheet::error(constQString & 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(constQString & plain)

Auxiliary function. Converts the plain text stringplain to a rich text formatted string with any HTML meta-characters escaped.

See alsoconvertFromPlainText().

Q3StyleSheetItem * Q3StyleSheet::item(constQString & name)

Returns the style calledname or 0 if there is no such style.

constQ3StyleSheetItem * Q3StyleSheet::item(constQString & name) const

This is an overloaded function.

Returns the style calledname or 0 if there is no such style (const version)

[static]bool Q3StyleSheet::mightBeRichText(constQString & text)

Returns true if the stringtext is likely to be rich text; otherwise returns false.

This function uses a fast and therefore simple heuristic. It mainly checks whether there is something that looks like a tag before the first line break. Although the result may be correct for common cases, there is no guarantee.

[virtual]void Q3StyleSheet::scaleFont(QFont & font,int logicalSize) const

Scales the fontfont to the appropriate physical point size corresponding to the logical font sizelogicalSize.

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.

See alsoQ3StyleSheetItem::logicalFontSize(),Q3StyleSheetItem::logicalFontSizeStep(), andQFont::setPointSize().

[static]void Q3StyleSheet::setDefaultSheet(Q3StyleSheet * sheet)

Sets the application-wide default style sheet tosheet, deleting any style sheet previously set. The ownership is transferred toQ3StyleSheet.

See alsodefaultSheet().

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp