Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Fonctions  · 

QSimpleRichText Class Reference

The QSimpleRichText class provides a small displayable piece of rich text. More...

#include <qsimplerichtext.h>

List of all member functions.

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 pageBreak = -1, const QColor & linkColor = Qt::blue, bool linkUnderline = TRUE )
  • ~QSimpleRichText ()
  • void setWidth ( int w )
  • void setWidth ( QPainter * p, int w )
  • void setDefaultFont ( const QFont & f )
  • int width () const
  • int widthUsed () const
  • int height () const
  • void adjustSize ()
  • 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  (obsolete)
  • QString context () const
  • QString anchorAt ( const QPoint & pos ) const
  • bool inText ( const QPoint & pos ) const

Detailed Description

The QSimpleRichText 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 QStyleSheet 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(). 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 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 QSimpleRichText to print in high resolution you should call setWidth(QPainter, int) so that the content will be laid out properly on the page.

See also Text Related Classes.


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 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:

    QSimpleRichText 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. 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.

The sheet 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 pageBreak = -1, const QColor & linkColor = Qt::blue, bool linkUnderline = TRUE )

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

This is a slightly more complex constructor for QSimpleRichText 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 QColorGroup's QColorGroup::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. 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.

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

This constructor is useful for creating a QSimpleRichText object suitable for printing. Set pageBreak to be the height of the contents area of the pages.

QSimpleRichText::~QSimpleRichText ()

Destroys the rich text object, freeing memory.

void QSimpleRichText::adjustSize ()

Adjusts the richt text object to a reasonable size.

See also setWidth().

QString QSimpleRichText::anchorAt ( const QPoint & pos ) const

Returns the anchor at the requested position, pos. An empty string is returned if no anchor is specified for this position.

QString QSimpleRichText::context () const

Returns the context of the rich text object. If no context has been specified in the constructor, a null string is returned. The context is the path to use to look up relative links, such as image tags and anchor references.

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

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.

Examples: action/application.cpp, application/application.cpp, helpviewer/helpwindow.cpp, and mdi/application.cpp.

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

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Use the version with clipRect instead. The region version has problems with larger documents on some platforms (on X11 regions internally are represented with 16bit coordinates).

int QSimpleRichText::height () const

Returns the height of the rich text object in pixels.

See also setWidth().

Examples: action/application.cpp, application/application.cpp, helpviewer/helpwindow.cpp, and mdi/application.cpp.

bool QSimpleRichText::inText ( const QPoint & pos ) const

Returns TRUE if pos is within a text line of the rich text object; otherwise returns FALSE.

void QSimpleRichText::setDefaultFont ( const QFont & f )

Sets the default font for the rich text object to f

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

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 height() and adjustSize().

Examples: action/application.cpp, application/application.cpp, helpviewer/helpwindow.cpp, and mdi/application.cpp.

void QSimpleRichText::setWidth ( int w )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the width of the rich text object to w pixels.

See also height() and adjustSize().

int QSimpleRichText::width () const

Returns the set width of the rich text object in pixels.

See also widthUsed().

int QSimpleRichText::widthUsed () const

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


This file is part of the Qt toolkit. Copyright © 1995-2005 Trolltech. All Rights Reserved.

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. Microsoft ouvre aux autres compilateurs C++ AMP, la spécification pour la conception d'applications parallèles C++ utilisant le GPU 22
  2. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  3. RIM : « 13 % des développeurs ont gagné plus de 100 000 $ sur l'AppWord », Qt et open-source au menu du BlackBerry DevCon Europe 0
  4. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 10
  5. BlackBerry 10 : premières images du prochain OS de RIM qui devrait intégrer des widgets et des tuiles inspirées de Windows Phone 0
  6. Adieu qmake, bienvenue qbs : Qt Building Suite, un outil déclaratif et extensible pour la compilation de projets Qt 17
  7. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
Page suivante

Le Qt Quarterly au hasard

Logo

Déployer dans le Bazaar

Qt Quarterly est la revue trimestrielle proposée par Nokia et à destination des développeurs Qt. Ces articles d'une grande qualité technique sont rédigés par des experts Qt. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 3.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web