Qt logo

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

Protected Members


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(). Currently, a small XML/CSS1 subset including embedded images 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 slighty different from other widgets, since a text view is a scrollable widget that naturally provies 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 and sufficient way to add reasonable online help facilities to applications. We will, however, extend it to some degree in future versions of Qt. Most likely some basic table support will be put in and a new class to provide rich text input.

For even more, like hypertext capabilities, see QTextBrowser.

Bugs and limitations:


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.

QString QTextView::context () const [virtual]

Returns the context of the view.

See also: text() and setText().

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.

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 QColorQTextView::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 wether or not links should be displayed underlined.

QMimeSourceFactoryQTextView::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 QBrushQTextView::paper ()

Returns the brush used to paint the background.

const QColorGroupQTextView::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 querable rich text object. This is not currently useful for applications.

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 wether 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 pergament 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 = QString::null ) [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.

The 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::setTextFormat ( Qt::TextFormat format )

Sets the text format to format. Possible choices are

QStyleSheetQTextView::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 * ) [virtual protected]

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.

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

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.

void QTextView::viewportMouseReleaseEvent ( QMouseEvent * ) [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.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