Home · Overviews · Examples 

QTextBrowser Class Reference
[com.trolltech.qt.gui module]

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

Inherits QTextEdit.


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

If you want to provide your users with an editable rich text editor, use QTextEdit. If you want a text browser without hypertext navigation use QTextEdit, and use QTextEdit::setReadOnly() to disable editing. If you just need to display a small piece of rich text use QLabel.

Document Source and Contents

The contents of QTextEdit are set with setHtml or setPlainText, but QTextBrowser also implements the setSource function, making it possible to use a named document as the source text. The name is looked up in a list of search paths and in the directory of the current document 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 connecting to the sourceChanged signal.

Navigation

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 anchorClicked signal is emitted when the user clicks an anchor. To override the default navigation behavior of the browser, call the setSource function to supply new document text in a slot connected to this signal.

If you want to load documents stored in the Qt resource system use qrc as the scheme in the URL to load. For example, for the document resource path :/docs/index.html use qrc:/docs/index.html as the URL with setSource.

See also QTextEdit and QTextDocument.


Copyright © 2008 Trolltech Trademarks
Qt Jambi 4.3.4_01