QTextBrowser Class Reference

[ QtGui module]

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

继承 QTextEdit .

方法

Qt Signals


详细描述

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

此类扩展 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 () 到 disable editing. If you just need to display a small piece of rich text use QLabel .

文档源和内容

The contents of QTextEdit are set with setHtml () 或 setPlainText (),但 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 () 信号。

导航

QTextBrowser provides backward () 和 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 (). To access local files, use file as the scheme in the URL.


方法文档编制

QTextBrowser.__init__ ( self , QWidget   parent  = None)

parent argument, if not None, causes self to be owned by Qt instead of PyQt.

构造空 QTextBrowser 采用父级 parent .

QTextBrowser.backward ( self )

This method is also a Qt slot with the C++ signature void backward() .

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.

另请参阅 forward () 和 backwardAvailable ().

int QTextBrowser.backwardHistoryCount ( self )

Returns the number of locations backward in the history.

该函数在 Qt 4.4 引入。

QTextBrowser.clearHistory ( self )

Clears the history of visited documents and disables the forward and backward navigation.

该函数在 Qt 4.2 引入。

另请参阅 backward () 和 forward ().

bool QTextBrowser.event ( self , QEvent   e )

重实现自 QObject.event ().

bool QTextBrowser.focusNextPrevChild ( self , bool  next )

重实现自 QWidget.focusNextPrevChild ().

QTextBrowser.focusOutEvent ( self , QFocusEvent   ev )

重实现自 QWidget.focusOutEvent ().

QTextBrowser.forward ( self )

This method is also a Qt slot with the C++ signature void forward() .

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.

另请参阅 backward () 和 forwardAvailable ().

int QTextBrowser.forwardHistoryCount ( self )

Returns the number of locations forward in the history.

该函数在 Qt 4.4 引入。

QString QTextBrowser.historyTitle ( self , int)

返回 documentTitle () of the HistoryItem.

Input 返回
i < 0 backward () history
i == 0 current, see QTextBrowser.source ()
i > 0 forward () history
 backaction.setToolTip(browser.historyTitle(-1));
 forwardaction.setToolTip(browser.historyTitle(+1));
			

该函数在 Qt 4.4 引入。

QUrl QTextBrowser.historyUrl ( self , int)

Returns the url of the HistoryItem.

Input 返回
i < 0 backward () history
i == 0 current, see QTextBrowser.source ()
i > 0 forward () history

该函数在 Qt 4.4 引入。

QTextBrowser.home ( self )

This method is also a Qt slot with the C++ signature void home() .

Changes the document displayed to be the first document from the history.

bool QTextBrowser.isBackwardAvailable ( self )

Returns true if the text browser can go backward in the document history using backward ().

该函数在 Qt 4.2 引入。

另请参阅 backwardAvailable () 和 backward ().

bool QTextBrowser.isForwardAvailable ( self )

Returns true if the text browser can go forward in the document history using forward ().

该函数在 Qt 4.2 引入。

另请参阅 forwardAvailable () 和 forward ().

QTextBrowser.keyPressEvent ( self , QKeyEvent   ev )

重实现自 QWidget.keyPressEvent ().

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 ()

QVariant QTextBrowser.loadResource ( self , int  type , QUrl   name )

重实现自 QTextEdit.loadResource ().

This function is called when the document is loaded and for each image in the document. The type indicates the type of resource to be loaded. An invalid QVariant is returned if the resource cannot be loaded.

The default implementation ignores type and tries to locate the resources by interpreting name as a file name. If it is not an absolute path it tries to find the file in the paths 的 searchPaths property and in the same directory as the current source. On success, the result is a QVariant that stores a QByteArray with the contents of the file.

If you reimplement this function, you can return other QVariant types. The table below shows which variant types are supported depending on the resource type:

ResourceType QVariant.Type
QTextDocument.HtmlResource QString or QByteArray
QTextDocument.ImageResource QImage , QPixmap or QByteArray
QTextDocument.StyleSheetResource QString or QByteArray

QTextBrowser.mouseMoveEvent ( self , QMouseEvent   ev )

重实现自 QWidget.mouseMoveEvent ().

QTextBrowser.mousePressEvent ( self , QMouseEvent   ev )

重实现自 QWidget.mousePressEvent ().

QTextBrowser.mouseReleaseEvent ( self , QMouseEvent   ev )

重实现自 QWidget.mouseReleaseEvent ().

bool QTextBrowser.openExternalLinks ( self )

bool QTextBrowser.openLinks ( self )

QTextBrowser.paintEvent ( self , QPaintEvent   e )

重实现自 QWidget.paintEvent ().

QTextBrowser.reload ( self )

This method is also a Qt slot with the C++ signature void reload() .

Reloads the current set source.

QStringList QTextBrowser.searchPaths ( self )

QTextBrowser.setOpenExternalLinks ( self , bool  open )

QTextBrowser.setOpenLinks ( self , bool  open )

QTextBrowser.setSearchPaths ( self , QStringList  paths )

QTextBrowser.setSource ( self , QUrl   name )

This method is also a Qt slot with the C++ signature void setSource(const QUrl&) .

QUrl QTextBrowser.source ( self )


Qt Signal Documentation

void anchorClicked (const QUrl&)

This is the default overload of this signal.

This signal is emitted when the user clicks an anchor. The URL referred to by the anchor is passed in link .

Note that the browser will automatically handle navigation to the location specified by link unless the openLinks property is set to false or you call setSource () in a slot connected. This mechanism is used to override the default navigation features of the browser.

void backwardAvailable (bool)

This is the default overload of this 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 forwardAvailable (bool)

This is the default overload of this 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 highlighted (const QUrl&)

This is the default overload of this signal.

This signal is emitted when the user has selected but not activated an anchor in the document. The URL referred to by the anchor is passed in link .

void highlighted (const QString&)

这是重载函数。

Convenience signal that allows connecting to a slot that takes just a QString , like for example QStatusBar 's message().

void historyChanged ()

This is the default overload of this signal.

This signal is emitted when the history changes.

该函数在 Qt 4.4 引入。

另请参阅 historyTitle () 和 historyUrl ().

void sourceChanged (const QUrl&)

This is the default overload of this signal.

This signal is emitted when the 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.