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  ·  Classes  ·  Annotées  ·  Hiérarchie  ·  Fonctions  ·  Structure  · 

QTextView Class Reference


A sophisticated single-page rich text viewer. More...

#include <qtextview.h>

Inherits QScrollView.

Inherited by QTextBrowser.

List of all member functions.

Public Members

  • QTextView ( QWidget * parent=0, const char * name=0 ) 
  • QTextView ( const QString & text, const QString & context = QString::null, QWidget * parent=0, const char * name=0 ) 
  • ~QTextView () 
  • virtual void setText ( const QString & text, const QString & context ) 
  • void setText ( const QString & text ) 
  • virtual QString text () const
  • virtual QString context () const
  • TextFormat textFormat () const
  • void setTextFormat ( TextFormat ) 
  • QStyleSheet* styleSheet () const
  • void setStyleSheet ( QStyleSheet * styleSheet ) 
  • void setPaper ( const QBrush & pap ) 
  • const QBrush& paper () 
  • const QBrush& paper () const
  • void setPaperColorGroup ( const QColorGroup & colgrp ) 
  • const QColorGroup& paperColorGroup () const
  • void setLinkColor ( const QColor & ) 
  • const QColor& linkColor () const
  • void setLinkUnderline ( bool ) 
  • bool linkUnderline () const
  • void setMimeSourceFactory ( QMimeSourceFactory * factory ) 
  • QMimeSourceFactory* mimeSourceFactory () const
  • QString documentTitle () const
  • virtual int heightForWidth ( int w ) const
  • void append ( const QString & text ) 
  • bool hasSelectedText () const
  • QString selectedText () const

Public Slots

Protected Members

Properties

TypeNameREADWRITEOptions
QStringtexttextsetText 
TextFormattextFormattextFormatsetTextFormat 
QBrushpaperpapersetPaper 
QColorGrouppaperColorGrouppaperColorGroupsetPaperColorGroup 
QColorlinkColorlinkColorsetLinkColor 
boollinkUnderlinelinkUnderlinesetLinkUnderline 
QStringdocumentTitledocumentTitle  

Detailed Description

A sophisticated single-page rich text viewer.

Unlike QSimpleRichText, which merely draws small pieces of rich text, a QTextView is a real widget, with scrollbars when necessary, for showing large text documents.

The rendering style and available tags are defined by a styleSheet(). Custom tags can be created and placed in a custom style sheet. Change the style sheet with \l{setStyleSheet()}; see QStyleSheet for details. Currently, a small XML/CSS1 subset including embedded images and tables is supported. See QStyleSheet for details. Possible images within the text document are resolved by using a QMimeSourceFactory. See setMimeSourceFactory() for details.

Using QTextView is quite similar to QLabel. It's mainly a call to setText() to set the contents. Setting the background color is slightly different from other widgets, since a text view is a scrollable widget that naturally provides a scrolling background. You can specify the colorgroup of the displayed text with setPaperColorGroup() or directly define the paper background with setPaper(). QTextView supports both plain color and complex pixmap backgrounds.

Note that we do not intend to add a full-featured web browser widget to Qt (since that would easily double Qt's size and only few applications would benefit from it). In particular, the rich text support in Qt is supposed to provide a fast, portable and sufficient way to add reasonable online help facilities to applications. We will, however, extend it to some degree in future versions of Qt.

For even more, like hypertext capabilities, see QTextBrowser.


Member Function Documentation

QTextView::QTextView ( QWidget * parent=0, const char * name=0 )

Constructs an empty QTextView with the standard parent and name optional arguments.

QTextView::QTextView ( const QString & text, const QString & context = QString::null, QWidget * parent=0, const char * name=0 )

Constructs a QTextView displaying the contents text with context context, with the standard parent and name optional arguments.

QTextView::~QTextView ()

Destructs the view.

void QTextView::append ( const QString & text )

Appends text to the current text.

Useful for log viewers.

Warning: This function has known problems (incorrect painting and layouting). If this problem occures to you, use setText( text() + theNewText ) instead. The new richtext engine, which is part of Qt 3.0, is able to handle append(), insert(), etc. properly.

QString QTextView::context () const [virtual]

Returns the context of the view.

See also text() and setText().

void QTextView::copy () [slot]

Copies the marked text to the clipboard.

QString QTextView::documentTitle () const

Returns the document title parsed from the content.

void QTextView::drawContentsOffset ( QPainter * p, int ox, int oy, int cx, int cy, int cw, int ch ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.

void QTextView::focusInEvent ( QFocusEvent * ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

void QTextView::focusOutEvent ( QFocusEvent * ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

bool QTextView::hasSelectedText () const

Returns TRUE if there is any text selected, FALSE otherwise.

See also selectedText().

int QTextView::heightForWidth ( int w ) const [virtual]

Returns the height of the view given a width of w.

Reimplemented from QWidget.

void QTextView::keyPressEvent ( QKeyEvent * e ) [virtual protected]

Provides scrolling and paging.

Reimplemented from QWidget.

const QColor& QTextView::linkColor () const

Returns the current link color.

The color may either have been set with setLinkColor() or stem from the document's body tag.

See also setLinkColor().

bool QTextView::linkUnderline () const

Returns whether or not links should be displayed underlined.

QMimeSourceFactory* QTextView::mimeSourceFactory () const

Returns the current mime source factory for the view.

See also setMimeSourceFactory().

void QTextView::paletteChange ( const QPalette & p ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

const QBrush& QTextView::paper ()

Returns the brush used to paint the background.

const QBrush& QTextView::paper () const

Returns the brush used to paint the background.

const QColorGroup& QTextView::paperColorGroup () const

Returns the colorgroup of the paper.

See also setPaperColorGroup() and setPaper().

void QTextView::resizeEvent ( QResizeEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

QRichText& QTextView::richText () const [protected]

Returns the document defining the view as drawable and queryable rich text object. This is not currently useful for applications.

void QTextView::selectAll () [slot]

Selects all text.

QString QTextView::selectedText () const

Returns a copy of the selected text in plain text format.

See also hasSelectedText().

void QTextView::setLinkColor ( const QColor & col )

Sets the color used to display links in the document to col.

See also linkColor().

void QTextView::setLinkUnderline ( bool u )

Defines whether or not links should be displayed underlined.

void QTextView::setMimeSourceFactory ( QMimeSourceFactory * factory )

Sets the mime source factory for the view. The factory is used to resolve named references within rich text documents. If no factory has been specified, the text view uses the default factory QMimeSourceFactory::defaultFactory().

Ownership of factory is not transferred to make it possible for several text view widgets to share the same mime source.

See also mimeSourceFactory().

void QTextView::setPaper ( const QBrush & pap )

Sets the brush to use as the background to pap.

This may be a nice parchment or marble pixmap or simply another plain color.

Technically, setPaper() is just a convenience function to set the base brush of the paperColorGroup().

See also paper().

void QTextView::setPaperColorGroup ( const QColorGroup & colgrp )

Sets the full colorgroup of the paper to colgrp. If not specified otherwise in the document itself, any text will use QColorGroup::text(). The background will be painted with QColorGroup::brush(QColorGroup::Base).

See also paperColorGroup() and setPaper().

void QTextView::setStyleSheet ( QStyleSheet * styleSheet )

Sets the style sheet of the view.

See also styleSheet().

void QTextView::setText ( const QString & text, const QString & context ) [virtual]

Changes the contents of the view to the string text and the context to context.

text may be interpreted either as plain text or as rich text, depending on the textFormat(). The default setting is AutoText, i.e. the text view autodetects the format from text.

For rich text the rendering style and available tags are defined by a styleSheet(); see QStyleSheet for details.

The optional context is used to resolve references within the text document, for example image sources. It is passed directly to the mimeSourceFactory() when quering data.

See also text() and setTextFormat().

Reimplemented in QTextBrowser.

void QTextView::setText ( const QString & text )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Changes the contents of the view to the string text.

text may be interpreted either as plain text or as rich text, depending on the textFormat(). The default setting is AutoText, i.e. the text view autodetects the format from text.

This function calls setText( text, QString::null ), i.e. it sets a text without any context.

See also text() and setTextFormat().

void QTextView::setTextFormat ( Qt::TextFormat format )

Sets the text format to format. Possible choices are

  • PlainText - all characters are displayed verbatim, including all blanks and linebreaks.
  • RichText - rich text rendering. The available styles are defined in the default stylesheet QStyleSheet::defaultSheet().
  • AutoText - this is also the default. The label autodetects which rendering style suits best, PlainText or RichText. Technically, this is done by using the QStyleSheet::mightBeRichText() heuristic.

void QTextView::showEvent ( QShowEvent * ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

QStyleSheet* QTextView::styleSheet () const

Returns the current style sheet of the view.

See also setStyleSheet().

QString QTextView::text () const [virtual]

Returns the contents of the view.

See also context() and setText().

Qt::TextFormat QTextView::textFormat() const

Returns the current text format.

See also setTextFormat().

void QTextView::viewportMouseMoveEvent ( QMouseEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.

void QTextView::viewportMousePressEvent ( QMouseEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.

void QTextView::viewportMouseReleaseEvent ( QMouseEvent * e ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.

void QTextView::viewportResizeEvent ( QResizeEvent * ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.


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


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. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 94
  2. Apercevoir la troisième dimension ou l'utilisation multithreadée d'OpenGL dans Qt, un article des Qt Quarterly traduit par Guillaume Belz 0
  3. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 43
  4. Les développeurs ignorent-ils trop les failles découvertes dans leur code ? Prenez-vous en compte les remarques des autres ? 17
  5. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  6. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 9
Page suivante

Le Qt Labs au hasard

Logo

QMake et au-delà, le retour

Les Qt Labs sont les laboratoires des développeurs de Qt, où ils peuvent partager des impressions sur le framework, son utilisation, ce que pourrait être son futur. 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 2.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