Qt logo

QSimpleRichText Class Reference


A small displayable piece of rich text. More...

#include <qsimplerichtext.h>

List of all member functions.

Public Members


Detailed Description

A small displayable piece of rich text.

This class encapsulates simple richt text usage where a string is interpretted as richt text and can be drawn. This is in particular useful if you want to display some rich text in a custom widget.

Once created, the rich text object can be queried for its width(), height() and the actual width used (see widthUsed()). Most importantly, it can be drawn on any given QPainter with draw(). QSimpleRichText can also be used to implement hypertext or active text facilities by using anchor().

Once constructed from a string, the contents cannot be changed, only resized. If the contents should change, just throw the rich text object away and make a new one with the new contents.

For large documents, see QTextView or QTextBrowser.


Member Function Documentation

QSimpleRichText::QSimpleRichText ( const QString & text, const QFont & fnt, const QString & context = QString::null, const QStyleSheet * s = 0 )

Constructs a QSimpleRichText from the rich text string text and the font fnt.

The font is used as basis for the text rendering. When using rich text rendering on a certain widget w, you would regularily specify the widget's font as shown in the following code example:

  QSimpleRichText* t = new QSimpleRichText( contents, w->font() );

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

s is an optional stylesheet. If it is 0, the default style sheet will be used (see QStyleSheet::defaultSheet() ).

QSimpleRichText::~QSimpleRichText ()

Destructs the document, freeing memory.

QString QSimpleRichText::anchor ( QPainter * p, const QPoint & pos )

Returns the anchor at the requested position. The QPainter is needed for font size calculations. An empty string is returned if no anchor is specified for this certain position.

QString QSimpleRichText::context () const

Returns the context of the rich text document. If no context has been specified in the constructor, a null string is returned.

void QSimpleRichText::draw ( QPainter * p, int x, int y, const QRegion & clipRegion, const QColorGroup & cg, const QBrush * paper = 0 ) const

Draws the formatted text with p, at position (x,\a y), clipped to clipRegion. Colors from the cg are used as needed, and if not 0, *paper is used as the background brush.

Note that the display code is highly optimized to reduce flicker, so passing a brush for paper is preferrable to simply clearing the area to be painted and then calling this without a brush.

This is a convenience function if there's no palette but just a cologroup available. If you have a palette, pass this instead of cg.

void QSimpleRichText::draw ( QPainter * p, int x, int y, const QRegion & clipRegion, const QPalette & pal, const QBrush * paper = 0 ) const

Draws the formatted text with p, at position (x,\a y), clipped to clipRegion. Colors from the palette pal are used as needed, and if not 0, *paper is used as the background brush.

Note that the display code is highly optimized to reduce flicker, so passing a brush for paper is preferrable to simply clearing the area to be painted and then calling this without a brush.

int QSimpleRichText::height () const

Returns the height of the document, in pixels.

See also: setWidth().

void QSimpleRichText::setWidth ( QPainter * p, int w )

Sets the width of the document to w pixels, recalculating the layout as if it were to be drawn with p.

See also: height().

int QSimpleRichText::width () const

Returns the set width of the document, in pixels.

See also: widthUsed().

int QSimpleRichText::widthUsed () const

Returns the width in pixels that is actually used by the document. This can be smaller or wider than the set width.

It may be wider, for example, if the text contains images or non-breakable words that are already wider than the available space. It's smaller when the document only consists of lines that do not fill the width completely.

See also: width().


Search the documentation, FAQ, qt-interest archive and more (uses www.troll.no):


This file is part of the Qt toolkit, copyright © 1995-99 Troll Tech, all rights reserved.


Copyright İ 1999 Troll TechTrademarks
Qt version 2.0.2