QSimpleRichText(3qt)

NAME
QSimpleRichText - A small displayable piece of rich text

#include <qsimplerichtext.h>

  Public Members
QSimpleRichText ( const QString & text, const QFont & fnt, const QString & context = QString::null, const QStyleSheet * sheet = 0 )
QSimpleRichText ( const QString & text, const QFont & fnt, const QString & context, const QStyleSheet * sheet, const QMimeSourceFactory * factory, int verticalBreak = -1, const QColor & linkColor = Qt::blue, bool linkUnderline = TRUE )
~QSimpleRichText ()
void setWidth ( int )
void setWidth ( QPainter *, int )
int width () const
int widthUsed () const
int height () const
void adjustSize ()
void draw ( QPainter *, int x, int y, const QRegion & clipRegion, const QPalette & pal, const QBrush * paper = 0 ) const
void draw ( QPainter *, int x, int y, const QRegion & clipRegion, const QColorGroup & cg, const QBrush * paper = 0 ) const
QString context () const
QString anchorAt ( const QPoint & pos ) const
QString anchor ( QPainter * p, const QPoint & pos ) (obsolete)
bool inText ( const QPoint & pos ) const

DESCRIPTION
A small displayable piece of rich text.

This class encapsulates simple richt text usage where a string is interpreted as richt text and can be drawn. This is in particular useful if you want to display some rich text in a custom widget. A QStyleSheet is needed to actually understand and format rich text. Qt provides a default HTML-like style sheet but you may define custom style sheets.

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 anchorAt(). A hit test through inText() makes it possible to use simple rich text for text objects in editable drawing canvases.

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 * sheet = 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 regularly specify the widget's font as shown in the following code example:

  QSimpleRichText myrichtext( contents, mywidget->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.

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

QSimpleRichText::QSimpleRichText ( const QString & text, const QFont & fnt, const QString & context, const QStyleSheet * sheet, const QMimeSourceFactory * factory, int verticalBreak = -1, const QColor & linkColor = Qt::blue, bool linkUnderline = TRUE )
Another, more complex constructor for QSimpleRichText that takes an additional mime source factory factory, a vertical break parameter verticalBreak, a link color linkColor and a bool linkUnderline.

The constructor is useful to create a QSimpleRichText object suitable for printing. Set verticalBreak to be the height of the contents area of the pages.

QSimpleRichText::~QSimpleRichText ()
Destructs the document, freeing memory.

void QSimpleRichText::adjustSize ()
Adjusts the richt text document to a reasonable size.

See also setWidth().

QString QSimpleRichText::anchor ( QPainter *, const QPoint & pos )
This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

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.

This function will be removed in 3.0.

QString QSimpleRichText::anchorAt ( const QPoint & pos ) const
Returns the anchor at the requested position. 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 QPalette & pal, const QBrush * paper = 0 ) const
Draws the formatted text with p, at position (x, 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 preferable to simply clearing the area to be painted and then calling this without a brush.

void QSimpleRichText::draw ( QPainter * p, int x, int y, const QRegion & clipRegion, const QColorGroup & cg, const QBrush * paper = 0 ) const
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Draws the formatted text with p, at position (x, 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 preferable 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 color group available. If you have a palette, pass this instead of cg.

int QSimpleRichText::height () const
Returns the height of the document, in pixels.

See also setWidth().

bool QSimpleRichText::inText ( const QPoint & pos ) const
Returns whether pos is within a text line of the document or not.

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.

Passing a painter is useful when you intend to draw on devices other than the screen, like for example a QPrinter.

See also height() and adjustSize().

void QSimpleRichText::setWidth ( int w )
Sets the width of the document to w pixels.

See also height() and adjustSize().

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().

SEE ALSO
http://doc.trolltech.com/qsimplerichtext.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 make our job much simpler. Thank you.

In case of content or formattting problems with this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qsimplerichtext.3qt) and the Qt version (2.3.5).