QTextBrowser

Section: Misc. Reference Manual Pages (3qt)
Updated: 2 February 2007
Index Return to Main Contents
 

NAME

QTextBrowser - Rich text browser with hypertext navigation  

SYNOPSIS

#include <qtextbrowser.h>

Inherits QTextEdit.

 

Public Members


QTextBrowser ( QWidget * parent = 0, const char * name = 0 )

QString source () const
 

Public Slots


virtual void setSource ( const QString & name )

virtual void backward ()

virtual void forward ()

virtual void home ()

virtual void reload ()
 

Signals


void backwardAvailable ( bool available )

void forwardAvailable ( bool available )

void sourceChanged ( const QString & src )

void highlighted ( const QString & link )

void linkClicked ( const QString & link )

void anchorClicked ( const QString & name, const QString & link )
 

Properties


bool modified - whether the contents have been modified (read only)

bool overwriteMode - this text browser's overwrite mode (read only)

bool readOnly - whether the contents are read only (read only)

QString source - the name of the displayed document

int undoDepth - this text browser's undo depth (read only)

bool undoRedoEnabled - whether undo and redo are enabled (read only)
 

Protected Members


virtual void keyPressEvent ( QKeyEvent * e )
 

DESCRIPTION

The QTextBrowser class provides a rich text browser with hypertext navigation.

This class extends QTextEdit (in read-only mode), adding some navigation functionality so that users can follow links in hypertext documents. The contents of QTextEdit is set with setText(), but QTextBrowser has an additional function, setSource(), which makes it possible to set the text to a named document. The name is looked up in the text view's mime source factory. If a document name ends with an anchor (for example, "#anchor"), the text browser automatically scrolls to that position (using scrollToAnchor()). When the user clicks on a hyperlink, the browser will call setSource() itself, with the link's href value as argument. You can track the current source by connetion to the sourceChanged() signal.

QTextBrowser provides backward() and forward() slots which you can use to implement Back and Forward buttons. The home() slot sets the text to the very first document displayed. The linkClicked() signal is emitted when the user clicks a link.

By using QTextEdit::setMimeSourceFactory() you can provide your own subclass of QMimeSourceFactory. This makes it possible to access data from anywhere, for example from a network or from a database. See QMimeSourceFactory::data() for details.

If you intend using the mime factory to read the data directly from the file system, you may have to specify the encoding for the file extension you are using. For example:


mimeSourceFactory()->setExtensionType("qml", "text/utf8");
This is to ensure that the factory is able to resolve the document names.

QTextBrowser interprets the tags it processes in accordance with the default style sheet. Change the style sheet with setStyleSheet(); see QStyleSheet for details.

If you want to pro