QStyleSheet(3qt)

NAME
QStyleSheet - Collection of styles for rich text rendering and a generator of tags

SYNOPSIS
#include <qstylesheet.h>

Inherits QObject.

  Public Members
QStyleSheet ( QObject * parent = 0, const char * name = 0 )
virtual ~QStyleSheet ()
QStyleSheetItem * item ( const QString & name )
const QStyleSheetItem * item ( const QString & name ) const
virtual QTextCustomItem * tag ( const QString & name, const QMap<QString, QString> & attr, const QString & context, const QMimeSourceFactory & factory, bool emptyTag, QTextDocument * doc ) const
virtual void scaleFont ( QFont & font, int logicalSize ) const
virtual void error ( const QString & msg ) const

  Static Public Members
QStyleSheet * defaultSheet ()
void setDefaultSheet ( QStyleSheet * sheet )
QString escape ( const QString & plain )
QString convertFromPlainText ( const QString & plain, QStyleSheetItem::WhiteSpaceMode mode = QStyleSheetItem::WhiteSpacePre )
bool mightBeRichText ( const QString & text )

DESCRIPTION
The QStyleSheet class is a collection of styles for rich text rendering and a generator of tags.

By creating QStyleSheetItem 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 or a 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.

The default QStyleSheet 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 <center>.nf
 | A sublevel heading.
 | A sub-sublevel heading.
 | Headings of lesser importance.
 | A left-aligned paragraph. Adjust the alignment with the
 | A centered paragraph.
 | An indented paragraph that is useful for quotes.
 | An unordered list. You can also pass a type argument to
define the bullet style. The default is
 | An ordered list. You can also pass a type argument to
define the enumeration label style. The default is
 | A list item. This tag can be used only within the context
of
 | A list of definitions, consisting of terms and descriptions.
 | A term in a list of definitions. This tag can be used only
in the context of
 | A description in a list of definitions. This tag can be
used only in the context of
 | For larger chunks of code. Whitespaces in the contents are
preserved. For small bits of code use the inline-style
</center>

Anchors and links are done with a single tag: <center>.nf
A link is created by using an
</center>

The default character style bindings are <center>.nf
</center>

Special elements are: <center>.nf
Special tags | Notes
 | An image. The image name for the mime source factory is
given in the source attribute, for example
 | A horizontal line.
 | A line break.
</center>

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.

<center>.nf
</center>

See also Graphics Classes, Help System, and Text Related Classes.

MEMBER FUNCTION DOCUMENTATION

QStyleSheet::QStyleSheet ( QObject * parent = 0, const char * name = 0 )
Creates a style sheet called name, with parent 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.

QStyleSheet::~QStyleSheet () [virtual]
Destroys the style sheet. All styles inserted into the style sheet will be deleted.

QString QStyleSheet::convertFromPlainText ( const QString & plain, QStyleSheetItem::WhiteSpaceMode mode = QStyleSheetItem::WhiteSpacePre ) [static]
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 QStyleSheetItem::WhiteSpacePre (no wrapping, all whitespaces preserved) and QStyleSheetItem::WhiteSpaceNormal (wrapping, simplified whitespaces).

See also escape().

Examples:

QStyleSheet * QStyleSheet::defaultSheet () [static]
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.

See also setDefaultSheet().

void QStyleSheet::error ( const QString & msg ) const [virtual]
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.

QString QStyleSheet::escape ( const QString & plain ) [static]
Auxiliary function. Converts the plain text string plain to a rich text formatted string with any HTML meta-characters escaped.

See also convertFromPlainText().

QStyleSheetItem * QStyleSheet::item ( const QString & name )
Returns the style called name or 0 if there is no such style.

const QStyleSheetItem * QStyleSheet::item ( const QString & name ) const
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

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

bool QStyleSheet::mightBeRichText ( const QString & text ) [static]
Returns TRUE if the string text 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.

void QStyleSheet::scaleFont ( QFont & font, int logicalSize ) const [virtual]
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.

See also QStyleSheetItem::logicalFontSize(), QStyleSheetItem::logicalFontSizeStep(), and QFont::setPointSize().

void QStyleSheet::setDefaultSheet ( QStyleSheet * sheet ) [static]
Sets the application-wide default style sheet to sheet, deleting any style sheet previously set. The ownership is transferred to QStyleSheet.

See also defaultSheet().

QTextCustomItem * QStyleSheet::tag ( const QString & name, const QMap<QString, QString> & attr, const QString & context, const QMimeSourceFactory & factory, bool emptyTag, QTextDocument * doc ) const [virtual]
This function is under development and is subject to change.

Generates an internal object for the tag called name, given the attributes attr, and using additional information provided by the mime source factory factory.

context is the optional context of the document, i.e. the path to look for relative links. This becomes important if the text contains relative references, for example within image tags. QSimpleRichText always uses the default mime source factory (see QMimeSourceFactory::defaultFactory()) to resolve these references. The context will then be used to calculate the absolute path. See QMimeSourceFactory::makeAbsolute() for details.

emptyTag and doc are for internal use only.

This function should not be used in application code.

SEE ALSO
http://doc.trolltech.com/qstylesheet.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you.

The definitive Qt documentation is provided in HTML format; it is located at $QTDIR/doc/html and can be read using Qt Assistant or with a web browser. This man page is provided as a convenience for those users who prefer man pages, although this format is not officially supported by Trolltech.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qstylesheet.3) and the Qt version (3.3.5).