返回介绍

QTextBrowser Class

发布于 2019-10-04 15:03:15 字数 7353 浏览 1089 评论 0 收藏 0

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

#include <qtextbrowser.h>

Inherits QTextEdit.

List of all member functions.

Public Members

  • QTextBrowser ( QWidget*parent = 0, constchar*name = 0 )
  • QString source () const

Public Slots

  • virtual void setSource ( constQString&name )
  • virtual void backward ()
  • virtual void forward ()
  • virtual void home ()
  • virtual void reload ()

Signals

  • void backwardAvailable ( boolavailable )
  • void forwardAvailable ( boolavailable )
  • void highlighted ( constQString&href )
  • void linkClicked ( constQString&link )

Properties

  • QString source- the name of the currently displayed document

Protected Members

  • virtual void keyPressEvent ( QKeyEvent*e )

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

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.

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.

See also Advanced Widgets, Help System and Text Related Classes.


Member Function Documentation

QTextBrowser::QTextBrowser ( QWidget*parent = 0, constchar*name = 0 )

Constructs an empty QTextBrowser with parent parent called name.

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

Example: helpviewer/helpwindow.cpp.

void QTextBrowser::backwardAvailable ( boolavailable ) [signal]

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

Example: helpviewer/helpwindow.cpp.

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

Example: helpviewer/helpwindow.cpp.

void QTextBrowser::forwardAvailable ( boolavailable ) [signal]

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

Example: helpviewer/helpwindow.cpp.

void QTextBrowser::highlighted ( constQString&href ) [signal]

This signal is emitted when the user has selected but not activated a link in the document. href is the value of the href tag in the link.

Example: helpviewer/helpwindow.cpp.

void QTextBrowser::home () [virtual slot]

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

Example: helpviewer/helpwindow.cpp.

void QTextBrowser::keyPressEvent ( QKeyEvent*e ) [virtual protected]

The event e is used to provide the following keyboard shortcuts:
  • Alt+Left Arrow - backward()
  • Alt+Right Arrow - forward()
  • Alt+Up Arrow - home()

Reimplemented from QTextEdit.

void QTextBrowser::linkClicked ( constQString&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.

void QTextBrowser::reload () [virtual slot]

Reloads the current set source

void QTextBrowser::setSource ( constQString&name ) [virtual slot]

Sets the name of the currently displayed document to name. See the "source" property for details.

QString QTextBrowser::source () const

Returns the name of the currently displayed document. See the "source" property for details.


Property Documentation

QString source

This property holds the name of the currently displayed document.

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

Setting this property uses the mimeSourceFactory to lookup the named document. 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().

If you are using the filesystem access capabilities of the mime source factory, you must ensure that the factory knows about the encoding of specified files; otherwise no data will be available. The default factory handles a couple of common file extensions such as *.html and *.txt with reasonable defaults. See QMimeSourceFactory::data() for details.

Set this property's value with setSource() and get this property's value with source().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文