The Q3SimpleRichText class provides a small displayable piece of rich text. More...
#include <Q3SimpleRichText>
This class is part of the Qt 3 support library. It is provided to keep old source code working. We strongly advise against using it in new code. See Porting to Qt 4 for more information.
Q3SimpleRichText ( const QString & text, const QFont & fnt, const QString & context = QString(), const Q3StyleSheet * sheet = 0 ) | |
Q3SimpleRichText ( const QString & text, const QFont & fnt, const QString & context, const Q3StyleSheet * sheet, const Q3MimeSourceFactory * factory, int pageBreak = -1, const QColor & linkColor = Qt::blue, bool linkUnderline = true ) | |
~Q3SimpleRichText () | |
void | adjustSize () |
QString | anchorAt ( const QPoint & pos ) const |
QString | context () const |
void | draw ( QPainter * p, int x, int y, const QRect & clipRect, const QColorGroup & cg, const QBrush * paper = 0 ) const |
void | draw ( QPainter * p, int x, int y, const QRegion & clipRegion, const QColorGroup & cg, const QBrush * paper = 0 ) const |
int | height () const |
bool | inText ( const QPoint & pos ) const |
void | setDefaultFont ( const QFont & f ) |
void | setWidth ( QPainter * p, int w ) |
void | setWidth ( int w ) |
int | width () const |
int | widthUsed () const |
The Q3SimpleRichText class provides a small displayable piece of rich text.
This class encapsulates simple rich text usage in which a string is interpreted as rich text and can be drawn. This is particularly useful if you want to display some rich text in a custom widget. A Q3StyleSheet is needed to interpret the tags and format the 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(). Q3SimpleRichText 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 change, just throw the rich text object away and make a new one with the new contents.
For large documents use QTextEdit or QTextBrowser. For very small items of rich text you can use a QLabel.
If you are using Q3SimpleRichText to print in high resolution you should call setWidth(QPainter, int) so that the content will be laid out properly on the page.
Constructs a Q3SimpleRichText from the rich text string text and the font fnt.
The font is used as a basis for the text rendering. When using rich text rendering on a widget w, you would normally specify the widget's font, for example:
Q3SimpleRichText myrichtext(contents, mywidget->font());
context is the optional context of the rich text object. This becomes important if text contains relative references, for example within image tags. Q3SimpleRichText always uses the default mime source factory (see Q3MimeSourceFactory::defaultFactory()) to resolve those references. The context will then be used to calculate the absolute path. See Q3MimeSourceFactory::makeAbsolute() for details.
The sheet is an optional style sheet. If it is 0, the default style sheet will be used (see Q3StyleSheet::defaultSheet()).
Constructs a Q3SimpleRichText from the rich text string text and the font fnt.
This is a slightly more complex constructor for Q3SimpleRichText that takes an additional mime source factory factory, a page break parameter pageBreak and a bool linkUnderline. linkColor is only provided for compatibility, but has no effect, as QPalette::link() color is used now.
context is the optional context of the rich text object. This becomes important if text contains relative references, for example within image tags. Q3SimpleRichText always uses the default mime source factory (see Q3MimeSourceFactory::defaultFactory()) to resolve those references. The context will then be used to calculate the absolute path. See Q3MimeSourceFactory::makeAbsolute() for details.
The sheet is an optional style sheet. If it is 0, the default style sheet will be used (see Q3StyleSheet::defaultSheet()).
This constructor is useful for creating a Q3SimpleRichText object suitable for printing. Set pageBreak to be the height of the contents area of the pages.
Destroys the rich text object, freeing memory.
Adjusts the rich text object to a reasonable size.
See also setWidth().
Returns the anchor at the requested position, pos. An empty string is returned if no anchor is specified for this position.
Returns the context of the rich text object. If no context has been specified in the constructor, an empty string is returned. The context is the path to use to look up relative links, such as image tags and anchor references.
Draws the formatted text with painter p, at position (x, y), clipped to clipRect. The clipping rectangle is given in the rich text object's coordinates translated by (x, y). Passing an null rectangle results in no clipping. Colors from the color group 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.
Use the version with clipRect instead of this clipRegion version, since this region version has problems with larger documents on some platforms (on X11 regions internally are represented with 16-bit coordinates).
Returns the height of the rich text object in pixels.
See also setWidth().
Returns true if pos is within a text line of the rich text object; otherwise returns false.
Sets the default font for the rich text object to f
Sets the width of the rich text object to w pixels, recalculating the layout as if it were to be drawn with painter p.
Passing a painter is useful when you intend drawing on devices other than the screen, for example a QPrinter.
See also width(), height(), and adjustSize().
This is an overloaded function.
Sets the width of the rich text object to w pixels.
See also height() and adjustSize().
Returns the set width of the rich text object in pixels.
See also setWidth() and widthUsed().
Returns the width in pixels that is actually used by the rich text object. 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 object only consists of lines that do not fill the width completely.
See also width().
© 2008-2011 Nokia Corporation and/or its subsidiaries. Nokia, Qt and their respective logos are trademarks of Nokia Corporation in Finland and/or other countries worldwide.
All other trademarks are property of their respective owners. Privacy Policy
Licensees holding valid Qt Commercial licenses may use this document in accordance with the Qt Commercial License Agreement provided with the Software or, alternatively, in accordance with the terms contained in a written agreement between you and Nokia.
Alternatively, this document may be used under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.