QWebEngineView¶
The
QWebEngineView
class provides a widget that is used to view and edit web documents. More…
Synopsis¶
Functions¶
def
findText
(arg__1, arg__2, arg__3)def
findText
(subString[, options=QWebEnginePage.FindFlags()])def
hasSelection
()def
history
()def
icon
()def
iconUrl
()def
load
(request)def
load
(url)def
page
()def
pageAction
(action)def
selectedText
()def
setContent
(data[, mimeType=””[, baseUrl=QUrl()]])def
setHtml
(html[, baseUrl=QUrl()])def
setPage
(page)def
setUrl
(url)def
setZoomFactor
(factor)def
settings
()def
title
()def
triggerPageAction
(action[, checked=false])def
url
()def
zoomFactor
()
Virtual functions¶
def
createWindow
(type)
Slots¶
Signals¶
def
iconChanged
(arg__1)def
iconUrlChanged
(arg__1)def
loadFinished
(arg__1)def
loadProgress
(progress)def
loadStarted
()def
renderProcessTerminated
(terminationStatus, exitCode)def
selectionChanged
()def
titleChanged
(title)def
urlChanged
(arg__1)
Detailed Description¶
A web view is the main widget component of the Qt WebEngine web browsing module. It can be used in various applications to display web content live from the Internet.
A web site can be loaded to a web view with the
load()
function. The GET method is always used to load URLs.Like all Qt widgets, the
show()
function must be invoked in order to display the web view. The snippet below illustrates this:QWebEngineView *view = new QWebEngineView(parent); view->load(QUrl("http://qt-project.org/")); view->show();Alternatively,
setUrl()
can be used to load a web site. If you have the HTML content readily available, you can usesetHtml()
instead.The
loadStarted()
signal is emitted when the view begins loading and theloadProgress()
signal is emitted whenever an element of the web view completes loading, such as an embedded image or a script. TheloadFinished()
signal is emitted when the view has been loaded completely. Its argument, eithertrue
orfalse
, indicates whether loading was successful or failed.The
page()
function returns a pointer to a web page object. AQWebEngineView
contains aQWebEnginePage
, which in turn allows access to theQWebEngineHistory
in the page’s context.The title of an HTML document can be accessed with the
title()
property. Additionally, a web site may specify an icon, which can be accessed using theicon()
or its URL using theiconUrl()
property. If the title or the icon changes, the correspondingtitleChanged()
,iconChanged()
andiconUrlChanged()
signals will be emitted. ThezoomFactor()
property enables zooming the contents of the web page by a scale factor.The widget features a context menu that is tailored to the element at hand, and includes actions useful in a browser. For a custom context menu, or for embedding actions in a menu or toolbar, the individual actions are available via
pageAction()
. The web view maintains the state of the returned actions, but allows modification of action properties such astext
oricon
. The action semantics can also be triggered directly throughtriggerPageAction()
.If you want to provide support for web sites that allow the user to open new windows, such as pop-up windows, you can subclass
QWebEngineView
and reimplement thecreateWindow()
function.See also
WebEngine Widgets Simple Browser Example WebEngine Content Manipulation Example WebEngine Markdown Editor Example
- class PySide2.QtWebEngineWidgets.QWebEngineView([parent=Q_NULLPTR])¶
- param parent:
Constructs an empty web view with the parent
parent
.See also
- PySide2.QtWebEngineWidgets.QWebEngineView.back()¶
Convenience slot that loads the previous document in the list of documents built by navigating links. Does nothing if there is no previous document.
It is equivalent to:
view->page()->triggerAction(QWebEnginePage::Back);
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.createWindow(type)¶
- Parameters:
type –
WebWindowType
- Return type:
This function is called from the
createWindow()
method of the associatedQWebEnginePage
each time the page wants to create a new window of the giventype
. For example, when a JavaScript request to open a document in a new window is issued.Note
If the
createWindow()
method of the associated page is reimplemented, this method is not called, unless explicitly done so in the reimplementation.See also
- PySide2.QtWebEngineWidgets.QWebEngineView.findText(arg__1, arg__2, arg__3)¶
- Parameters:
arg__1 – str
arg__2 –
FindFlags
arg__3 – object
- PySide2.QtWebEngineWidgets.QWebEngineView.findText(subString[, options=QWebEnginePage.FindFlags()])
- Parameters:
subString – str
options –
FindFlags
- PySide2.QtWebEngineWidgets.QWebEngineView.forward()¶
Convenience slot that loads the next document in the list of documents built by navigating links. Does nothing if there is no next document.
It is equivalent to:
view->page()->triggerAction(QWebEnginePage::Forward);
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.hasSelection()¶
- Return type:
bool
This property holds Whether this page contains selected content or not..
By default, this property is
false
.See also
- PySide2.QtWebEngineWidgets.QWebEngineView.history()¶
- Return type:
Returns a pointer to the view’s history of navigated web pages.
It is equivalent to:
view->page()->history();
- PySide2.QtWebEngineWidgets.QWebEngineView.icon()¶
- Return type:
This property holds The icon associated with the page currently viewed..
By default, this property contains a null icon.
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.iconChanged(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtGui.QIcon
- PySide2.QtWebEngineWidgets.QWebEngineView.iconUrl()¶
- Return type:
This property holds The URL of the icon associated with the page currently viewed..
By default, this property contains an empty URL.
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.iconUrlChanged(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtCore.QUrl
- PySide2.QtWebEngineWidgets.QWebEngineView.load(url)¶
- Parameters:
url –
PySide2.QtCore.QUrl
- PySide2.QtWebEngineWidgets.QWebEngineView.load(request)
- Parameters:
- PySide2.QtWebEngineWidgets.QWebEngineView.loadFinished(arg__1)¶
- Parameters:
arg__1 – bool
- PySide2.QtWebEngineWidgets.QWebEngineView.loadProgress(progress)¶
- Parameters:
progress – int
- PySide2.QtWebEngineWidgets.QWebEngineView.loadStarted()¶
- PySide2.QtWebEngineWidgets.QWebEngineView.page()¶
- Return type:
Returns a pointer to the underlying web page.
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.pageAction(action)¶
- Parameters:
action –
WebAction
- Return type:
Returns a pointer to a
QAction
that encapsulates the specified web actionaction
.
- PySide2.QtWebEngineWidgets.QWebEngineView.reload()¶
Reloads the current document.
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.renderProcessTerminated(terminationStatus, exitCode)¶
- Parameters:
terminationStatus –
RenderProcessTerminationStatus
exitCode – int
- PySide2.QtWebEngineWidgets.QWebEngineView.selectedText()¶
- Return type:
str
This property holds The text currently selected..
By default, this property contains an empty string.
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.selectionChanged()¶
- PySide2.QtWebEngineWidgets.QWebEngineView.setContent(data[, mimeType=""[, baseUrl=QUrl()]])¶
- Parameters:
data –
PySide2.QtCore.QByteArray
mimeType – str
baseUrl –
PySide2.QtCore.QUrl
Sets the content of the web view to
data
. If themimeType
argument is empty, it is assumed that the content istext/plain,charset=US-ASCII
.External objects referenced in the content are located relative to
baseUrl
. For external objects to be loaded,baseUrl
cannot be empty.The data is loaded immediately; external objects are loaded asynchronously.
- PySide2.QtWebEngineWidgets.QWebEngineView.setHtml(html[, baseUrl=QUrl()])¶
- Parameters:
html – str
baseUrl –
PySide2.QtCore.QUrl
Sets the content of the web view to the specified
html
content.External objects, such as stylesheets or images referenced in the HTML document, are located relative to
baseUrl
. For external objects to be loaded,baseUrl
cannot be empty. For example, ifhtml
is retrieved fromhttp://www.example.com/documents/overview.html
, which is the base URL, then an image referenced with the relative URL,diagram.png
, should be athttp://www.example.com/documents/diagram.png
.The HTML document is loaded immediately, whereas external objects are loaded asynchronously.
When using this method, Qt WebEngine assumes that external resources, such as JavaScript programs or style sheets, are encoded in UTF-8 unless otherwise specified. For example, the encoding of an external script can be specified through the
charset
attribute of the HTML script tag. Alternatively, the encoding can be specified by the web server.This is a convenience function equivalent to
setContent(html, "text/html;charset=UTF-8", baseUrl)
.Warning
This function works only for HTML. For other MIME types (such as XHTML or SVG),
setContent()
should be used instead.Note
Content larger than 2 MB cannot be displayed, because converts the provided HTML to percent-encoding and places
data
: in front of it to create the URL that it navigates to. Thereby, the provided code becomes a URL that exceeds the 2 MB limit set by Chromium. If the content is too large, theloadFinished()
signal is triggered withsuccess=false
.See also
- PySide2.QtWebEngineWidgets.QWebEngineView.setPage(page)¶
- Parameters:
Makes
page
the new web page of the web view.The parent
QObject
of the provided page remains the owner of the object. If the current page is a child of the web view, it will be deleted.See also
- PySide2.QtWebEngineWidgets.QWebEngineView.setUrl(url)¶
- Parameters:
url –
PySide2.QtCore.QUrl
This property holds The URL of the web page currently viewed..
Setting this property clears the view and loads the URL.
By default, this property contains an empty, invalid URL.
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.setZoomFactor(factor)¶
- Parameters:
factor – float
This property holds The zoom factor for the view..
Valid values are within the range from
0.25
to5.0
. The default factor is1.0
.
- PySide2.QtWebEngineWidgets.QWebEngineView.settings()¶
- Return type:
Returns a pointer to the view or page specific settings object.
It is equivalent to:
view->page()->settings();
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.stop()¶
Convenience slot that stops loading the document.
It is equivalent to:
view->page()->triggerAction(QWebEnginePage::Stop);
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.title()¶
- Return type:
str
This property holds The title of the page as defined by the HTML
<title>
element..Equivalent to
title()
.See also
- PySide2.QtWebEngineWidgets.QWebEngineView.titleChanged(title)¶
- Parameters:
title – str
- PySide2.QtWebEngineWidgets.QWebEngineView.triggerPageAction(action[, checked=false])¶
- Parameters:
action –
WebAction
checked – bool
Triggers the specified
action
. If it is a checkable action, the specifiedchecked
state is assumed.The following example triggers the copy action and therefore copies any selected text to the clipboard.
view->triggerPageAction(QWebEnginePage::Copy);
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.url()¶
- Return type:
This property holds The URL of the web page currently viewed..
Setting this property clears the view and loads the URL.
By default, this property contains an empty, invalid URL.
See also
- PySide2.QtWebEngineWidgets.QWebEngineView.urlChanged(arg__1)¶
- Parameters:
arg__1 –
PySide2.QtCore.QUrl
- PySide2.QtWebEngineWidgets.QWebEngineView.zoomFactor()¶
- Return type:
float
This property holds The zoom factor for the view..
Valid values are within the range from
0.25
to5.0
. The default factor is1.0
.
© 2022 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.