QGIS API Documentation 4.5.0-Master (3b5d115045b)
Loading...
Searching...
No Matches
QgsWebEnginePage Class Reference

A wrapper around the QWebEnginePage class, adding extra functionality. More...

#include <qgswebenginepage.h>

Inheritance diagram for QgsWebEnginePage:

Signals

void loadFinished (bool ok)
 This signal is emitted when the page finishes loading content.
void loadProgress (int progress)
 This signal is emitted when the global progress status changes.
void loadStarted ()
 This signal is emitted when the page starts loading content.

Public Member Functions

 QgsWebEnginePage (QObject *parent=nullptr)
 Constructor for QgsWebEnginePage, with the specified parent widget.
 ~QgsWebEnginePage () override
QSize documentSize () const
 Returns the size of the page document, in pixels.
QWebEnginePage * page ()
 Returns a reference to the QWebEnginePage.
bool render (QPainter *painter, const QRectF &painterRect)
 Renders the web page contents to a painter.
bool setContent (const QByteArray &data, const QString &mimeType=QString(), const QUrl &baseUrl=QUrl(), bool blocking=false)
 Sets the content of the web page to data.
bool setHtml (const QString &html, const QUrl &baseUrl=QUrl(), bool blocking=false)
 Sets the content of this page to html.
bool setUrl (const QUrl &url, bool blocking=false)
 Sets the url of the web page to be displayed.

Static Public Member Functions

static bool printToPdfBlocking (const QString &html, const QString &pdfFileName, QString &errorMessage, int width, const QgsHtmlRenderSettings &settings=QgsHtmlRenderSettings(), QgsFeedback *feedback=nullptr)
 Renders HTML content to a PDF file asynchronously.
static bool printToPdfBlocking (const QUrl &url, const QString &pdfFileName, QString &errorMessage, int width, const QgsHtmlRenderSettings &settings=QgsHtmlRenderSettings(), QgsFeedback *feedback=nullptr)
 Renders HTML content to a PDF file asynchronously.
static bool renderBlocking (const QString &html, QPainter *painter, const QRectF &painterRect, QString &errorMessage, QSizeF &renderedSize, const QgsHtmlRenderSettings &settings=QgsHtmlRenderSettings(), QgsFeedback *feedback=nullptr)
 Renders HTML content to a painter asynchronously.
static bool renderBlocking (const QUrl &url, QPainter *painter, const QRectF &painterRect, QString &errorMessage, QSizeF &renderedSize, const QgsHtmlRenderSettings &settings=QgsHtmlRenderSettings(), QgsFeedback *feedback=nullptr)
 Renders HTML content to a painter asynchronously.

Detailed Description

A wrapper around the QWebEnginePage class, adding extra functionality.

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

Definition at line 47 of file qgswebenginepage.h.

Constructor & Destructor Documentation

◆ QgsWebEnginePage()

QgsWebEnginePage::QgsWebEnginePage ( QObject * parent = nullptr)

Constructor for QgsWebEnginePage, with the specified parent widget.

Definition at line 48 of file qgswebenginepage.cpp.

◆ ~QgsWebEnginePage()

QgsWebEnginePage::~QgsWebEnginePage ( )
overridedefault

Member Function Documentation

◆ documentSize()

QSize QgsWebEnginePage::documentSize ( ) const

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.

Definition at line 154 of file qgswebenginepage.cpp.

◆ loadFinished

void QgsWebEnginePage::loadFinished ( bool ok)
signal

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.

◆ loadProgress

void QgsWebEnginePage::loadProgress ( int progress)
signal

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.

◆ loadStarted

void QgsWebEnginePage::loadStarted ( )
signal

This signal is emitted when the page starts loading content.

◆ page()

QWebEnginePage * QgsWebEnginePage::page ( )

Returns a reference to the QWebEnginePage.

Note
Not available in Python bindings

Definition at line 60 of file qgswebenginepage.cpp.

◆ printToPdfBlocking() [1/2]

bool QgsWebEnginePage::printToPdfBlocking ( const QString & html,
const QString & pdfFileName,
QString & errorMessage,
int width,
const QgsHtmlRenderSettings & settings = QgsHtmlRenderSettings(),
QgsFeedback * feedback = nullptr )
static

Renders HTML content to a PDF file asynchronously.

This method is safe to call on either the main or background threads, and will safely ensure that the main thread event loop is NOT run during the HTML rendering or PDF generation.

Parameters
htmlHTML content
pdfFileNamedestination filename for PDF
errorMessagewill be set to a descriptive error message if the printing fails
widthpage width
settingsoptional HTML render settings
feedbackoptional feedback for early cancellation
Returns
true if the printing was successful
Since
QGIS 4.4

Definition at line 340 of file qgswebenginepage.cpp.

◆ printToPdfBlocking() [2/2]

bool QgsWebEnginePage::printToPdfBlocking ( const QUrl & url,
const QString & pdfFileName,
QString & errorMessage,
int width,
const QgsHtmlRenderSettings & settings = QgsHtmlRenderSettings(),
QgsFeedback * feedback = nullptr )
static

Renders HTML content to a PDF file asynchronously.

This method is safe to call on either the main or background threads, and will safely ensure that the main thread event loop is NOT run during the HTML rendering or PDF generation.

Parameters
urlURL of HTML content
pdfFileNamedestination filename for PDF
errorMessagewill be set to a descriptive error message if the printing fails
widthpage width
settingsoptional HTML render settings
feedbackoptional feedback for early cancellation
Returns
true if the printing was successful
Since
QGIS 4.4

Definition at line 365 of file qgswebenginepage.cpp.

◆ render()

bool QgsWebEnginePage::render ( QPainter * painter,
const QRectF & painterRect )

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.
This method requires a QGIS build with PDF4Qt library support.
Returns
true if rendering was successful
Exceptions
QgsNotSupportedExceptionon QGIS builds without PDF4Qt library support.

Definition at line 246 of file qgswebenginepage.cpp.

◆ renderBlocking() [1/2]

bool QgsWebEnginePage::renderBlocking ( const QString & html,
QPainter * painter,
const QRectF & painterRect,
QString & errorMessage,
QSizeF & renderedSize,
const QgsHtmlRenderSettings & settings = QgsHtmlRenderSettings(),
QgsFeedback * feedback = nullptr )
static

Renders HTML content to a painter asynchronously.

Content will be rendered as vector objects.

This method is safe to call on either the main or background threads, and will safely ensure that the main thread event loop is NOT run during the HTML rendering.

Parameters
htmlHTML content
painterdestination QPainter
painterRectspecifies the target rectangle for the page in painter coordinates
errorMessagewill be set to a descriptive error message if the printing fails
renderedSizewill be set to the actual size of the rendered HTML
settingsoptional HTML render settings
feedbackoptional feedback for early cancellation
Warning
This method requires a QGIS build with PDF4Qt library support.
Returns
true if rendering was successful
Exceptions
QgsNotSupportedExceptionon QGIS builds without PDF4Qt library support.
Since
QGIS 4.4

Definition at line 378 of file qgswebenginepage.cpp.

◆ renderBlocking() [2/2]

bool QgsWebEnginePage::renderBlocking ( const QUrl & url,
QPainter * painter,
const QRectF & painterRect,
QString & errorMessage,
QSizeF & renderedSize,
const QgsHtmlRenderSettings & settings = QgsHtmlRenderSettings(),
QgsFeedback * feedback = nullptr )
static

Renders HTML content to a painter asynchronously.

Content will be rendered as vector objects.

This method is safe to call on either the main or background threads, and will safely ensure that the main thread event loop is NOT run during the HTML rendering.

Parameters
urlURL of HTML content
painterdestination QPainter
painterRectspecifies the target rectangle for the page in painter coordinates
errorMessagewill be set to a descriptive error message if the printing fails
renderedSizewill be set to the actual size of the rendered HTML
settingsoptional HTML render settings
feedbackoptional feedback for early cancellation
Warning
This method requires a QGIS build with PDF4Qt library support.
Returns
true if rendering was successful
Exceptions
QgsNotSupportedExceptionon QGIS builds without PDF4Qt library support.
Since
QGIS 4.4

Definition at line 408 of file qgswebenginepage.cpp.

◆ setContent()

bool QgsWebEnginePage::setContent ( const QByteArray & data,
const QString & mimeType = QString(),
const QUrl & baseUrl = QUrl(),
bool blocking = false )

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.
Returns
true if loading was successful

Definition at line 65 of file qgswebenginepage.cpp.

◆ setHtml()

bool QgsWebEnginePage::setHtml ( const QString & html,
const QUrl & baseUrl = QUrl(),
bool blocking = false )

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.
Returns
true if loading was successful

Definition at line 94 of file qgswebenginepage.cpp.

◆ setUrl()

bool QgsWebEnginePage::setUrl ( const QUrl & url,
bool blocking = false )

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.
Returns
true if loading was successful

Definition at line 124 of file qgswebenginepage.cpp.


The documentation for this class was generated from the following files: