Class: QgsWebEnginePage

A wrapper around the QWebEnginePage class, adding extra functionality.

Warning

This class is only available on QGIS builds with WebEngine support enabled.

Added in version 3.36.

List of all members, including inherited members

Class Hierarchy

Inheritance diagram of qgis.core.QgsWebEnginePage

Base classes

QObject

Methods

documentSize

Returns the size of the page document, in pixels.

render

Renders the web page contents to a painter.

setContent

Sets the content of the web page to data.

setHtml

Sets the content of this page to html.

setUrl

Sets the url of the web page to be displayed.

Signals

loadFinished

This signal is emitted when the page finishes loading content.

loadProgress

This signal is emitted when the global progress status changes.

loadStarted

This signal is emitted when the page starts loading content.

class qgis.core.QgsWebEnginePage[source]

Bases: QObject

__init__(parent: QObject | None = None)

Constructor for QgsWebEnginePage, with the specified parent widget.

Parameters:

parent (Optional[QObject] = None)

documentSize(self) QSize[source]

Returns the size of the page document, in pixels.

Warning

If the page content was NOT loaded using a blocking method, then this method involves running the event loop on the current thread. Take care when calling from the main thread as incorrect use will result in crashes.

Return type:

QSize

signal loadFinished(ok: bool)[source]

This signal is emitted when the page finishes loading content.

This signal is independent of script execution or page rendering.

ok will indicate whether the load was successful or any error occurred.

Parameters:

ok (bool)

signal loadProgress(progress: int)[source]

This signal is emitted when the global progress status changes.

The current value is provided by progress and scales from 0 to 100. It accumulates changes from all the child frames.

Parameters:

progress (int)

signal loadStarted[source]

This signal is emitted when the page starts loading content.

render(self, painter: QPainter | None, painterRect: QRectF) bool[source]

Renders the web page contents to a painter. Content will be rendered as vector objects.

The painterRect argument specifies the target rectangle for the page in painter coordinates.

Warning

This method involves running the event loop on the current thread. Take care when calling from the main thread as incorrect use will result in crashes.

Warning

This method requires a QGIS build with PDF4Qt library support.

Return type:

bool

Returns:

True if rendering was successful

Raises:

QgsNotSupportedException – on QGIS builds without PDF4Qt library support.

Parameters:
  • painter (Optional[QPainter])

  • painterRect (QRectF)

setContent(self, data: QByteArray | bytes | bytearray | memoryview, mimeType: str | None = '', baseUrl: QUrl = QUrl(), blocking: bool = False) bool[source]

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

The baseUrl is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets.

If blocking is True then the call will block while the HTML is loaded. Otherwise the html is loaded immediately; external objects are loaded asynchronously.

Warning

Setting blocking to True involves running the event loop on the current thread. Take care when calling from the main thread as incorrect use will result in crashes.

Return type:

bool

Returns:

True if loading was successful

Parameters:
  • data (Union[QByteArray, bytes, bytearray, memoryview])

  • mimeType (Optional[str] = '')

  • baseUrl (QUrl = QUrl())

  • blocking (bool = False)

setHtml(self, html: str | None, baseUrl: QUrl = QUrl(), blocking: bool = False) bool[source]

Sets the content of this page to html.

The baseUrl is optional and used to resolve relative URLs in the document, such as referenced images or stylesheets.

If blocking is True then the call will block while the HTML is loaded. Otherwise the html is loaded immediately; external objects are loaded asynchronously.

Note

This function works only for HTML, for other mime types (such as XHTML and SVG) setContent() should be used instead.

Warning

Setting blocking to True involves running the event loop on the current thread. Take care when calling from the main thread as incorrect use will result in crashes.

Return type:

bool

Returns:

True if loading was successful

Parameters:
  • html (Optional[str])

  • baseUrl (QUrl = QUrl())

  • blocking (bool = False)

setUrl(self, url: QUrl, blocking: bool = False) bool[source]

Sets the url of the web page to be displayed.

Setting this property clears the page and loads the URL.

If blocking is True then the call will block while the HTML is loaded. Otherwise the html is loaded immediately; external objects are loaded asynchronously.

Warning

Setting blocking to True involves running the event loop on the current thread. Take care when calling from the main thread as incorrect use will result in crashes.

Return type:

bool

Returns:

True if loading was successful

Parameters:
  • url (QUrl)

  • blocking (bool = False)