PySide6.QtWidgets.QTextBrowser¶
- class QTextBrowser¶
The
QTextBrowserclass provides a rich text browser with hypertext navigation. More…Synopsis¶
Properties¶
searchPathsᅟ- The search paths used by the text browser to find supporting contentsourceᅟ- The name of the displayed documentsourceTypeᅟ- The type of the displayed document
Methods¶
def
__init__()def
clearHistory()def
historyTitle()def
historyUrl()def
openLinks()def
searchPaths()def
setOpenLinks()def
setSearchPaths()def
source()def
sourceType()
Virtual methods¶
def
backward()def
doSetSource()def
forward()def
home()def
reload()
Slots¶
def
setSource()
Signals¶
def
anchorClicked()def
highlighted()def
historyChanged()def
sourceChanged()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
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 useQTextEdit, and usesetReadOnly()to disable editing. If you just need to display a small piece of rich text useQLabel.The contents of
QTextEditare set withsetHtml()orsetPlainText(), butQTextBrowseralso implements thesetSource()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 (usingscrollToAnchor()). When the user clicks on a hyperlink, the browser will callsetSource()itself with the link’shrefvalue as argument. You can track the current source by connecting to thesourceChanged()signal.If you want to load documents stored in the Qt resource system use
qrcas the scheme in the URL to load. For example, for the document resource path:/docs/index.htmluseqrc:/docs/index.htmlas the URL withsetSource().See also
Note
Properties can be used directly when
from __feature__ import true_propertyis used or via accessor functions otherwise.- property openExternalLinksᅟ: bool¶
Specifies whether
QTextBrowsershould automatically open links to external sources using QDesktopServices::openUrl() instead of emitting theanchorClickedsignal. Links are considered external if their scheme is neither file or qrc.The default value is false.
- Access functions:
- property openLinksᅟ: bool¶
This property specifies whether
QTextBrowsershould automatically open links the user tries to activate by mouse or keyboard.Regardless of the value of this property the
anchorClickedsignal is always emitted.The default value is true.
- Access functions:
- property searchPathsᅟ: list of strings¶
This property holds the search paths used by the text browser to find supporting content.
QTextBrowseruses this list to locate images and documents.By default, this property contains an empty string list.
- Access functions:
This property holds the name of the displayed document..
This is a an invalid url if no document is displayed or if the source is unknown.
When setting this property
QTextBrowsertries to find a document with the specified name in the paths of thesearchPathsproperty and directory of the current source, unless the value is an absolute file path. It also checks for optional anchors and scrolls the document accordinglyIf 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 QTextDocument::setHtml() or QTextDocument::setMarkdown(), depending on whether the filename ends with any of the known Markdown file extensions.If you would like to avoid automatic type detection and specify the type explicitly, call
setSource()rather than setting this property.By default, this property contains an empty URL.
- Access functions:
- property sourceTypeᅟ: QTextDocument.ResourceType¶
This property holds the type of the displayed document.
This is QTextDocument::UnknownResource if no document is displayed or if the type of the source is unknown. Otherwise it holds the type that was detected, or the type that was specified when
setSource()was called.- Access functions:
Constructs an empty
QTextBrowserwith parentparent.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
linkunless theopenLinksproperty is set to false or you callsetSource()in a slot connected. This mechanism is used to override the default navigation features of the browser.- 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.
See also
- backwardAvailable(available)¶
- Parameters:
available – bool
This signal is emitted when the availability of
backward()changes.availableis false when the user is athome(); otherwise it is true.- backwardHistoryCount()¶
- Return type:
int
Returns the number of locations backward in the history.
- clearHistory()¶
Clears the history of visited documents and disables the forward and backward navigation.
See also
- doSetSource(name[, type=QTextDocument.UnknownResource])¶
- Parameters:
name –
QUrltype –
ResourceType
Attempts to load the document at the given
urlwith the specifiedtype.setSource()calls doSetSource. In Qt 5,setSource(const QUrl &url) was virtual. In Qt 6, doSetSource() is virtual instead, so that it can be overridden in subclasses.- 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.
See also
- forwardAvailable(available)¶
- Parameters:
available – bool
This signal is emitted when the availability of
forward()changes.availableis true after the user navigatesbackward()and false when the user navigates or goesforward().- forwardHistoryCount()¶
- Return type:
int
Returns the number of locations forward in the history.
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.- historyChanged()¶
This signal is emitted when the history changes.
See also
- historyTitle(i)¶
- Parameters:
i – int
- Return type:
str
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
Returns the
documentTitle()of the HistoryItem.Input
Return
i< 0backward()historyi== 0current, see
source()i> 0forward()historybackaction.setToolTip(browser.historyTitle(-1)) forwardaction.setToolTip(browser.historyTitle(+1))
Returns the url of the HistoryItem.
Input
Return
i< 0backward()historyi== 0current, see
source()i> 0forward()history- home()¶
Changes the document displayed to be the first document from the history.
- isBackwardAvailable()¶
- Return type:
bool
Returns
trueif the text browser can go backward in the document history usingbackward().See also
- isForwardAvailable()¶
- Return type:
bool
Returns
trueif the text browser can go forward in the document history usingforward().See also
- openExternalLinks()¶
- Return type:
bool
See also
Getter of property
openExternalLinksᅟ.- openLinks()¶
- Return type:
bool
See also
Getter of property
openLinksᅟ.- reload()¶
Reloads the current set source.
- searchPaths()¶
- Return type:
list of strings
See also
Getter of property
searchPathsᅟ.- setOpenExternalLinks(open)¶
- Parameters:
open – bool
See also
Setter of property
openExternalLinksᅟ.- setOpenLinks(open)¶
- Parameters:
open – bool
See also
Setter of property
openLinksᅟ.- setSearchPaths(paths)¶
- Parameters:
paths – list of strings
See also
Setter of property
searchPathsᅟ.- setSource(name[, type=QTextDocument.UnknownResource])¶
- Parameters:
name –
QUrltype –
ResourceType
Attempts to load the document at the given
urlwith the specifiedtype.If
typeis UnknownResource (the default), the document type will be detected: that is, if the url ends with an extension of.md,.mkdor.markdown, the document will be loaded via QTextDocument::setMarkdown(); otherwise it will be loaded via QTextDocument::setHtml(). This detection can be bypassed by specifying thetypeexplicitly.See also
- source()¶
- Return type:
See also
Getter of property
sourceᅟ.This signal is emitted when the source has changed,
srcbeing the new source.Source changes happen both programmatically when calling
setSource(),forward(),backward()orhome()or when the user clicks on links or presses the equivalent key sequences.- sourceType()¶
- Return type:
Getter of property
sourceTypeᅟ.