QTextBrowser
The QTextBrowser
class provides a rich text browser with hypertext navigation. More…
Detailed Description
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 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()
.
-
class
QTextBrowser
([parent=None])
Constructs an empty QTextBrowser
with parent parent
.
-
PySide2.QtWidgets.QTextBrowser.
anchorClicked
(arg__1)
- Parameters
arg__1 – QUrl
-
PySide2.QtWidgets.QTextBrowser.
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.
-
PySide2.QtWidgets.QTextBrowser.
backwardAvailable
(arg__1)
- Parameters
arg__1 – bool
-
PySide2.QtWidgets.QTextBrowser.
backwardHistoryCount
()
- Return type
int
Returns the number of locations backward in the history.
-
PySide2.QtWidgets.QTextBrowser.
clearHistory
()
Clears the history of visited documents and disables the forward and backward navigation.
-
PySide2.QtWidgets.QTextBrowser.
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.
-
PySide2.QtWidgets.QTextBrowser.
forwardAvailable
(arg__1)
- Parameters
arg__1 – bool
-
PySide2.QtWidgets.QTextBrowser.
forwardHistoryCount
()
- Return type
int
Returns the number of locations forward in the history.
-
PySide2.QtWidgets.QTextBrowser.
highlighted
(arg__1)
- Parameters
arg__1 – unicode
-
PySide2.QtWidgets.QTextBrowser.
highlighted
(arg__1)
- Parameters
arg__1 – QUrl
-
PySide2.QtWidgets.QTextBrowser.
historyChanged
()
-
PySide2.QtWidgets.QTextBrowser.
historyTitle
(arg__1)
- Parameters
arg__1 – int
- Return type
unicode
Returns the documentTitle()
of the HistoryItem.
backaction.setToolTip(browser.historyTitle(-1))
forwardaction.setToolTip(browser.historyTitle(+1))
-
PySide2.QtWidgets.QTextBrowser.
historyUrl
(arg__1)
- Parameters
arg__1 – int
- Return type
QUrl
Returns the url of the HistoryItem.
-
PySide2.QtWidgets.QTextBrowser.
home
()
Changes the document displayed to be the first document from the history.
-
PySide2.QtWidgets.QTextBrowser.
isBackwardAvailable
()
- Return type
bool
Returns true
if the text browser can go backward in the document history using backward()
.
-
PySide2.QtWidgets.QTextBrowser.
isForwardAvailable
()
- Return type
bool
Returns true
if the text browser can go forward in the document history using forward()
.
-
PySide2.QtWidgets.QTextBrowser.
openExternalLinks
()
- Return type
bool
-
PySide2.QtWidgets.QTextBrowser.
openLinks
()
- Return type
bool
-
PySide2.QtWidgets.QTextBrowser.
reload
()
Reloads the current set source.
-
PySide2.QtWidgets.QTextBrowser.
searchPaths
()
- Return type
list of strings
-
PySide2.QtWidgets.QTextBrowser.
setOpenExternalLinks
(open)
- Parameters
open – bool
-
PySide2.QtWidgets.QTextBrowser.
setOpenLinks
(open)
- Parameters
open – bool
-
PySide2.QtWidgets.QTextBrowser.
setSearchPaths
(paths)
- Parameters
paths – list of strings
-
PySide2.QtWidgets.QTextBrowser.
setSource
(name)
- Parameters
name – QUrl
-
PySide2.QtWidgets.QTextBrowser.
source
()
- Return type
QUrl
-
PySide2.QtWidgets.QTextBrowser.
sourceChanged
(arg__1)
- Parameters
arg__1 – QUrl
© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.