QWebEngineView

The QWebEngineView class provides a widget that is used to view and edit web documents. More

Synopsis

Functions

Virtual functions

Slots

Signals

Detailed Description

A web view is the main widget component of the Qt 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 use setHtml() instead.

The loadStarted() signal is emitted when the view begins loading and the loadProgress() signal is emitted whenever an element of the web view completes loading, such as an embedded image or a script. The loadFinished() signal is emitted when the view has been loaded completely. Its argument, either true or false , indicates whether loading was successful or failed.

The page() function returns a pointer to a web page object. A QWebEngineView contains a QWebEnginePage , which in turn allows access to the QWebEngineHistory 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 the icon() or its URL using the iconUrl() property. If the title or the icon changes, the corresponding titleChanged() , iconChanged() and iconUrlChanged() signals will be emitted. The zoomFactor() 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 as text or icon . The action semantics can also be triggered directly through triggerPageAction() .

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 the createWindow() function.

See also

WebEngine Widgets Simple Browser Example WebEngine Content Manipulation Example WebEngine Markdown Editor Example

class QWebEngineView([parent=Q_NULLPTR])
param parent:QWidget

Constructs an empty web view with the parent parent .

See also

load()

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);
PySide2.QtWebEngineWidgets.QWebEngineView.createWindow(type)
Parameters:typeWebWindowType
Return type:QWebEngineView

This function is called from the createWindow() method of the associated QWebEnginePage each time the page wants to create a new window of the given type . 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

createWindow()

PySide2.QtWebEngineWidgets.QWebEngineView.findText(subString[, options=QWebEnginePage.FindFlags()])
Parameters:
  • subString – unicode
  • optionsFindFlags
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

back() pageAction()

PySide2.QtWebEngineWidgets.QWebEngineView.hasSelection()
Return type:bool
PySide2.QtWebEngineWidgets.QWebEngineView.history()
Return type:QWebEngineHistory

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:QIcon
PySide2.QtWebEngineWidgets.QWebEngineView.iconChanged(arg__1)
Parameters:arg__1QIcon
PySide2.QtWebEngineWidgets.QWebEngineView.iconUrl()
Return type:QUrl
PySide2.QtWebEngineWidgets.QWebEngineView.iconUrlChanged(arg__1)
Parameters:arg__1QUrl
PySide2.QtWebEngineWidgets.QWebEngineView.load(url)
Parameters:urlQUrl

Loads the specified url and displays it.

Note

The view remains the same until enough data has arrived to display the new URL.

See also

setUrl() url() urlChanged() fromUserInput()

PySide2.QtWebEngineWidgets.QWebEngineView.load(request)
Parameters:requestQWebEngineHttpRequest

Issues the specified request and loads the response.

See also

load() setUrl() url() urlChanged() fromUserInput()

PySide2.QtWebEngineWidgets.QWebEngineView.loadFinished(arg__1)
Parameters:arg__1bool
PySide2.QtWebEngineWidgets.QWebEngineView.loadProgress(progress)
Parameters:progressint
PySide2.QtWebEngineWidgets.QWebEngineView.loadStarted()
PySide2.QtWebEngineWidgets.QWebEngineView.page()
Return type:QWebEnginePage

Returns a pointer to the underlying web page.

See also

setPage()

PySide2.QtWebEngineWidgets.QWebEngineView.pageAction(action)
Parameters:actionWebAction
Return type:QAction

Returns a pointer to a QAction that encapsulates the specified web action action .

PySide2.QtWebEngineWidgets.QWebEngineView.reload()

Reloads the current document.

PySide2.QtWebEngineWidgets.QWebEngineView.renderProcessTerminated(terminationStatus, exitCode)
Parameters:
  • terminationStatusRenderProcessTerminationStatus
  • exitCodeint
PySide2.QtWebEngineWidgets.QWebEngineView.selectedText()
Return type:unicode
PySide2.QtWebEngineWidgets.QWebEngineView.selectionChanged()
PySide2.QtWebEngineWidgets.QWebEngineView.setContent(data[, mimeType=""[, baseUrl=QUrl()]])
Parameters:
  • dataQByteArray
  • mimeType – unicode
  • baseUrlQUrl

Sets the content of the web view to data . If the mimeType argument is empty, it is assumed that the content is text/plain,charset=US-ASCII .

External objects referenced in the content are located relative to baseUrl .

The data is loaded immediately; external objects are loaded asynchronously.

See also

load() setHtml() toHtml()

PySide2.QtWebEngineWidgets.QWebEngineView.setHtml(html[, baseUrl=QUrl()])
Parameters:
  • html – unicode
  • baseUrlQUrl

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 .

The HTML document is loaded immediately, whereas external objects are loaded asynchronously.

When using this method, Qt 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, the loadFinished() signal is triggered with success=false .

See also

load() setContent() toHtml() setContent()

PySide2.QtWebEngineWidgets.QWebEngineView.setPage(page)
Parameters:pageQWebEnginePage

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

page()

PySide2.QtWebEngineWidgets.QWebEngineView.setUrl(url)
Parameters:urlQUrl

See also

url()

PySide2.QtWebEngineWidgets.QWebEngineView.setZoomFactor(factor)
Parameters:factorqreal

See also

zoomFactor()

PySide2.QtWebEngineWidgets.QWebEngineView.settings()
Return type:QWebEngineSettings

Returns a pointer to the view or page specific settings object.

It is equivalent to:

view->page()->settings();

See also

globalSettings()

PySide2.QtWebEngineWidgets.QWebEngineView.stop()

Convenience slot that stops loading the document.

It is equivalent to:

view->page()->triggerAction(QWebEnginePage::Stop);
PySide2.QtWebEngineWidgets.QWebEngineView.title()
Return type:unicode
PySide2.QtWebEngineWidgets.QWebEngineView.titleChanged(title)
Parameters:title – unicode
PySide2.QtWebEngineWidgets.QWebEngineView.triggerPageAction(action[, checked=false])
Parameters:
  • actionWebAction
  • checkedbool

Triggers the specified action . If it is a checkable action, the specified checked 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

pageAction()

PySide2.QtWebEngineWidgets.QWebEngineView.url()
Return type:QUrl

See also

setUrl()

PySide2.QtWebEngineWidgets.QWebEngineView.urlChanged(arg__1)
Parameters:arg__1QUrl
PySide2.QtWebEngineWidgets.QWebEngineView.zoomFactor()
Return type:qreal

See also

setZoomFactor()