QWebEngineView#

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

Inheritance diagram of PySide6.QtWebEngineWidgets.QWebEngineView

Synopsis#

Functions#

Virtual functions#

Slots#

Signals#

Static functions#

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:

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

class PySide6.QtWebEngineWidgets.QWebEngineView([parent=None])#
Parameters

parentPySide6.QtWidgets.QWidget

Constructs an empty web view with the parent parent.

See also

load()

PySide6.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)
PySide6.QtWebEngineWidgets.QWebEngineView.createStandardContextMenu()#
Return type

PySide6.QtWidgets.QMenu

Creates a standard context menu and returns a pointer to it.

PySide6.QtWebEngineWidgets.QWebEngineView.createWindow(type)#
Parameters

typeWebWindowType

Return type

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

PySide6.QtWebEngineWidgets.QWebEngineView.findText(subString[, options={}])#
Parameters
  • subString – str

  • optionsFindFlags

PySide6.QtWebEngineWidgets.QWebEngineView.findText(arg__1, arg__2, arg__3)
Parameters
  • arg__1 – str

  • arg__2FindFlags

  • arg__3 – object

static PySide6.QtWebEngineWidgets.QWebEngineView.forPage(page)#
Parameters

pagePySide6.QtWebEngineCore.QWebEnginePage

Return type

PySide6.QtWebEngineWidgets.QWebEngineView

Returns the view if any, associated with the page.

See also

page() setPage()

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

PySide6.QtWebEngineWidgets.QWebEngineView.hasSelection()#
Return type

bool

This property holds Whether this page contains selected content or not..

By default, this property is false.

PySide6.QtWebEngineWidgets.QWebEngineView.history()#
Return type

PySide6.QtWebEngineCore.QWebEngineHistory

Returns a pointer to the view’s history of navigated web pages.

It is equivalent to:

view.page().history()
PySide6.QtWebEngineWidgets.QWebEngineView.icon()#
Return type

PySide6.QtGui.QIcon

This property holds The icon associated with the page currently viewed..

By default, this property contains a null icon.

PySide6.QtWebEngineWidgets.QWebEngineView.iconChanged(arg__1)#
Parameters

arg__1PySide6.QtGui.QIcon

PySide6.QtWebEngineWidgets.QWebEngineView.iconUrl()#
Return type

PySide6.QtCore.QUrl

This property holds The URL of the icon associated with the page currently viewed..

By default, this property contains an empty URL.

PySide6.QtWebEngineWidgets.QWebEngineView.iconUrlChanged(arg__1)#
Parameters

arg__1PySide6.QtCore.QUrl

PySide6.QtWebEngineWidgets.QWebEngineView.lastContextMenuRequest()#
Return type

PySide6.QtWebEngineCore.QWebEngineContextMenuRequest

Returns additional data about the current context menu. It is only guaranteed to be valid during the call to the contextMenuEvent() .

PySide6.QtWebEngineWidgets.QWebEngineView.load(url)#
Parameters

urlPySide6.QtCore.QUrl

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

PySide6.QtWebEngineWidgets.QWebEngineView.load(request)
Parameters

requestPySide6.QtWebEngineCore.QWebEngineHttpRequest

Issues the specified request and loads the response.

See also

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

PySide6.QtWebEngineWidgets.QWebEngineView.loadFinished(arg__1)#
Parameters

arg__1 – bool

PySide6.QtWebEngineWidgets.QWebEngineView.loadProgress(progress)#
Parameters

progress – int

PySide6.QtWebEngineWidgets.QWebEngineView.loadStarted()#
PySide6.QtWebEngineWidgets.QWebEngineView.page()#
Return type

PySide6.QtWebEngineCore.QWebEnginePage

Returns a pointer to the underlying web page.

See also

setPage()

PySide6.QtWebEngineWidgets.QWebEngineView.pageAction(action)#
Parameters

actionWebAction

Return type

PySide6.QtGui.QAction

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

PySide6.QtWebEngineWidgets.QWebEngineView.pdfPrintingFinished(filePath, success)#
Parameters
  • filePath – str

  • success – bool

PySide6.QtWebEngineWidgets.QWebEngineView.print(printer)#
Parameters

printerPySide6.QtPrintSupport.QPrinter

Renders the current content of the page into a temporary PDF document, then prints it using printer.

The settings for creating and printing the PDF document will be retrieved from the printer object.

When finished the signal printFinished() is emitted with the true for success or false for failure.

It is the users responsibility to ensure the printer remains valid until printFinished() has been emitted.

Note

Printing runs on the browser process, which is by default not sandboxed.

Note

This function rasterizes the result when rendering onto printer. Please consider raising the default resolution of printer to at least 300 DPI or using printToPdf() to produce PDF file output more effectively.

PySide6.QtWebEngineWidgets.QWebEngineView.printFinished(success)#
Parameters

success – bool

PySide6.QtWebEngineWidgets.QWebEngineView.printRequested()#
PySide6.QtWebEngineWidgets.QWebEngineView.printToPdf(filePath[, layout=QPageLayout(QPageSize(QPageSize.A4), QPageLayout.Portrait, QMarginsF())[, ranges={}]])#
Parameters

Renders the current content of the page into a PDF document and saves it in the location specified in filePath. The page size and orientation of the produced PDF document are taken from the values specified in layout, while the range of pages printed is taken from ranges with the default being printing all pages.

This method issues an asynchronous request for printing the web page into a PDF and returns immediately. To be informed about the result of the request, connect to the signal pdfPrintingFinished() .

If a file already exists at the provided file path, it will be overwritten.

PySide6.QtWebEngineWidgets.QWebEngineView.reload()#

Reloads the current document.

PySide6.QtWebEngineWidgets.QWebEngineView.renderProcessTerminated(terminationStatus, exitCode)#
Parameters
PySide6.QtWebEngineWidgets.QWebEngineView.selectedText()#
Return type

str

This property holds The text currently selected..

By default, this property contains an empty string.

PySide6.QtWebEngineWidgets.QWebEngineView.selectionChanged()#
PySide6.QtWebEngineWidgets.QWebEngineView.setContent(data[, mimeType=""[, baseUrl=QUrl()]])#
Parameters

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. For external objects to be loaded, baseUrl cannot be empty.

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

See also

load() setHtml() toHtml()

PySide6.QtWebEngineWidgets.QWebEngineView.setHtml(html[, baseUrl=QUrl()])#
Parameters

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, if html is retrieved from http://www.example.com/documents/overview.html, which is the base URL, then an image referenced with the relative URL, diagram.png, should be at http://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, the loadFinished() signal is triggered with success=false.

See also

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

PySide6.QtWebEngineWidgets.QWebEngineView.setPage(page)#
Parameters

pagePySide6.QtWebEngineCore.QWebEnginePage

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

PySide6.QtWebEngineWidgets.QWebEngineView.setUrl(url)#
Parameters

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

load() urlChanged()

PySide6.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 to 5.0. The default factor is 1.0.

PySide6.QtWebEngineWidgets.QWebEngineView.settings()#
Return type

PySide6.QtWebEngineCore.QWebEngineSettings

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

It is equivalent to:

view.page().settings()
PySide6.QtWebEngineWidgets.QWebEngineView.stop()#

Convenience slot that stops loading the document.

It is equivalent to:

view.page().triggerAction(QWebEnginePage.Stop)
PySide6.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

titleChanged()

PySide6.QtWebEngineWidgets.QWebEngineView.titleChanged(title)#
Parameters

title – str

PySide6.QtWebEngineWidgets.QWebEngineView.triggerPageAction(action[, checked=false])#
Parameters

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

PySide6.QtWebEngineWidgets.QWebEngineView.url()#
Return type

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

load() urlChanged()

PySide6.QtWebEngineWidgets.QWebEngineView.urlChanged(arg__1)#
Parameters

arg__1PySide6.QtCore.QUrl

PySide6.QtWebEngineWidgets.QWebEngineView.zoomFactor()#
Return type

float

This property holds The zoom factor for the view..

Valid values are within the range from 0.25 to 5.0. The default factor is 1.0.