Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# QTextBrowser Class Reference

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

    #include <QTextBrowser>

Inherits QTextEdit.

- List of all members, including inherited members
- Compatibility members

### Writable Properties

- searchPaths : QStringList
- source : QString

- 6 writable properties inherited from QTextEdit
- 2 writable properties inherited from QViewport
- 5 writable properties inherited from QFrame
- 33 writable properties inherited from QWidget
- 1 writable property inherited from QObject

### Read-Only Properties

- modified : bool
- readOnly : bool
- undoRedoEnabled : bool

- 1 read-only property inherited from QTextEdit
- 1 read-only property inherited from QViewport
- 1 read-only property inherited from QFrame
- 24 read-only properties inherited from QWidget

### Public Functions

- QTextBrowser ( QWidget * parent = 0 )
- virtual QImage loadImage ( const QString & name )

- 20 public functions inherited from QTextEdit
- 4 public functions inherited from QViewport
- 2 public functions inherited from QFrame
- 83 public functions inherited from QWidget
- 24 public functions inherited from QObject
- 2 public functions inherited from QPaintDevice

### Public Slots

- virtual void backward ()
- virtual void forward ()
- virtual void home ()
- virtual void reload ()
- virtual void setSource ( const QString & name )

- 21 public slots inherited from QTextEdit
- 16 public slots inherited from QWidget
- 1 public slot inherited from QObject

### Signals

- void anchorClicked ( const QString & link )
- void backwardAvailable ( bool available )
- void forwardAvailable ( bool available )
- void highlighted ( const QString & link )
- void linkClicked ( const QString & link )
- void sourceChanged ( const QString & src )

- 3 signals inherited from QTextEdit
- 1 signal inherited from QObject

### Static Public Members

- 4 static public members inherited from QWidget
- 4 static public members inherited from QObject

### Protected Functions

- virtual void keyPressEvent ( QKeyEvent * ev )

- 1 protected function inherited from QTextEdit
- 17 protected functions inherited from QViewport
- 44 protected functions inherited from QWidget
- 9 protected functions inherited from QObject

## 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. The contents of QTextEdit are set with setHtml() or setPlainText(), but QTextBrowser also implements the setSource() function, making it possible to set the text to a named document. 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.

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.

If you want to provide your users with editable rich text 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 QSimpleRichText or QLabel.

## Property Documentation

### modified : bool

This property holds whether the contents of the text browser have been modified.

### readOnly : bool

This property holds whether the text browser is read-only.

### searchPaths : QStringList

This property holds the search paths used by the text browser to find supporting content.

QTextBrowser uses this list to locate images and documents.

Access functions:

- QStringList searchPaths () const
- void setSearchPaths ( const QStringList & paths )

### source : QString

This property holds the name of the displayed document.

This is a an empty string if no document is displayed or if the source is unknown.

When setting this property QTextBrowser tries to find a document with the specified name in the paths of the searchPaths property and directory of the current source, unless the value is an absolute file path. It also checks for optional anchors and scrolls the document accordingly

If the first tag in the document is `<qt type=detail>`, the document is displayed as a popup rather than as new document in the browser window itself. Otherwise, the document is displayed normally in the text browser with the text set to the contents of the named document with setText().

Access functions:

- QString source () const
- virtual void setSource ( const QString & name )

### undoRedoEnabled : bool

This property holds whether the text browser supports undo/redo operations.

## Member Function Documentation

### QTextBrowser::QTextBrowser ( QWidget * parent = 0 )

Constructs an empty QTextBrowser with parent parent.

### void QTextBrowser::anchorClicked ( const QString & link ) `[signal]`

This signal is emitted when the user clicks an anchor. The link is the value of the `href` i.e. the name of the target document.

See also linkClicked().

### void QTextBrowser::backward () `[virtual slot]`

Changes the document displayed to the previous document in the list of documents built by navigating links. Does nothing if there is no previous document.

See also forward() and backwardAvailable().

### void QTextBrowser::backwardAvailable ( bool available ) `[signal]`

This signal is emitted when the availability of backward() changes. available is false when the user is at home(); otherwise it is true.

### void QTextBrowser::forward () `[virtual slot]`

Changes the document displayed to the next document in the list of documents built by navigating links. Does nothing if there is no next document.

See also backward() and forwardAvailable().

### void QTextBrowser::forwardAvailable ( bool available ) `[signal]`

This signal is emitted when the availability of forward() changes. available is true after the user navigates backward() and false when the user navigates or goes forward().

### void QTextBrowser::highlighted ( const QString & link ) `[signal]`

This signal is emitted when the user has selected but not activated a link in the document. link is the value of the `href` i.e. the name of the target document.

### void QTextBrowser::home () `[virtual slot]`

Changes the document displayed to be the first document the browser displayed.

### void QTextBrowser::keyPressEvent ( QKeyEvent * ev ) `[virtual protected]`

The event ev is used to provide the following keyboard shortcuts:

Keypress | Action
--- | ---
Alt+Left Arrow | backward()
Alt+Right Arrow | forward()
Alt+Up Arrow | home()

Reimplemented from QWidget.

### void QTextBrowser::linkClicked ( const QString & link ) `[signal]`

This signal is emitted when the user clicks a link. The link is the value of the `href` i.e. the name of the target document.

The link will be the absolute location of the document, based on the value of the anchor's href tag and the current context of the document.

See also anchorClicked().

### QImage QTextBrowser::loadImage ( const QString & name ) `[virtual]`

This function is called when the document to display contains images. For each image loadImage is called at least once. name corresponds to the name attribute of QTextImageFormat or the source attribute of the html img tag.

The default implementation tries to locate the image by interpreting name as a file name. If it is not an absolute path it tries to find the image in the paths of the searchPaths property and in the same directory as the current source.

### void QTextBrowser::reload () `[virtual slot]`

Reloads the current set source.

### void QTextBrowser::sourceChanged ( const QString & src ) `[signal]`

This signal is emitted when the mime source has changed, src being the new source.

Source changes happen both programmatically when calling setSource(), forward(), backword() or home() or when the user clicks on links or presses the equivalent key sequences.