Qt 5.11 | Qt WebEngine | C++ Classes | QWebEngineView

Qt 5.11.3 Reference Documentation

# QWebEngineView Class

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

Header: | #include <QWebEngineView>
qmake: | QT += webenginewidgets
Since: | Qt 5.4

- List of all members, including inherited members

## Properties

hasSelection : const bool icon : const QIcon iconUrl : const QUrl selectedText : const QString | title : const QString url : QUrl zoomFactor : qreal

## Public Functions

| QWebEngineView(QWidget *parent = Q_NULLPTR)
virtual | ~QWebEngineView()
void | findText(const QString &subString, QWebEnginePage::FindFlags options = QWebEnginePage::FindFlags(), const QWebEngineCallback<bool> &resultCallback = QWebEngineCallback<bool>())
bool | hasSelection() const
QWebEngineHistory * | history() const
QIcon | icon() const
QUrl | iconUrl() const
void | load(const QUrl &url)
void | load(const QWebEngineHttpRequest &request)
QWebEnginePage * | page() const
QAction * | pageAction(QWebEnginePage::WebAction action) const
QString | selectedText() const
void | setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl())
void | setHtml(const QString &html, const QUrl &baseUrl = QUrl())
void | setPage(QWebEnginePage *page)
void | setUrl(const QUrl &url)
void | setZoomFactor(qreal factor)
QWebEngineSettings * | settings() const
QString | title() const
void | triggerPageAction(QWebEnginePage::WebAction action, bool checked = false)
QUrl | url() const
qreal | zoomFactor() const

## Reimplemented Public Functions

virtual QSize | sizeHint() const override

## Public Slots

void | back()
void | forward()
void | reload()
void | stop()

## Signals

void | iconChanged(const QIcon &)
void | iconUrlChanged(const QUrl &)
void | loadFinished(bool)
void | loadProgress(int progress)
void | loadStarted()
void | renderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode)
void | selectionChanged()
void | titleChanged(const QString &title)
void | urlChanged(const QUrl &)

## Protected Functions

virtual QWebEngineView * | createWindow(QWebEnginePage::WebWindowType type)

## Reimplemented Protected Functions

virtual void | contextMenuEvent(QContextMenuEvent *event) override
virtual void | dragEnterEvent(QDragEnterEvent *e) override
virtual void | dragLeaveEvent(QDragLeaveEvent *e) override
virtual void | dragMoveEvent(QDragMoveEvent *e) override
virtual void | dropEvent(QDropEvent *e) override
virtual bool | event(QEvent *ev) override
virtual void | hideEvent(QHideEvent *event) override
virtual void | showEvent(QShowEvent *event) override

## Detailed Description

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

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 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, and WebEngine Markdown Editor Example.

## Property Documentation

### hasSelection : const bool

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

By default, this property is `false`.

Access functions:

bool | hasSelection() const

See also selectionChanged().

### icon : const QIcon

This property holds the icon associated with the page currently viewed

By default, this property contains a null icon.

This property was introduced in Qt 5.7.

Access functions:

QIcon | icon() const

Notifier signal:

void | iconChanged(const QIcon &)

See also iconChanged(), iconUrl(), and iconUrlChanged().

### iconUrl : const QUrl

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

By default, this property contains an empty URL.

Access functions:

QUrl | iconUrl() const

Notifier signal:

void | iconUrlChanged(const QUrl &)

See also iconUrlChanged(), icon(), and iconChanged().

### selectedText : const QString

This property holds the text currently selected

By default, this property contains an empty string.

Access functions:

QString | selectedText() const

See also findText() and selectionChanged().

### title : const QString

This property holds the title of the web page currently viewed

By default, this property contains an empty string.

Access functions:

QString | title() const

See also titleChanged().

### url : 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.

Access functions:

QUrl | url() const
void | setUrl(const QUrl &url)

See also load() and urlChanged().

### zoomFactor : qreal

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

Access functions:

qreal | zoomFactor() const
void | setZoomFactor(qreal factor)

## Member Function Documentation

### QWebEngineView::QWebEngineView(QWidget *parent = Q_NULLPTR)

Default constructs an instance of QWebEngineView.

### `[virtual]` QWebEngineView::~QWebEngineView()

Destroys the instance of QWebEngineView. The destructor is virtual.

### `[slot]` void QWebEngineView::back()

### `[override virtual protected]` void QWebEngineView::contextMenuEvent(QContextMenuEvent *event)

### `[virtual protected]` QWebEngineView *QWebEngineView::createWindow(QWebEnginePage::WebWindowType type)

### `[override virtual protected]` void QWebEngineView::dragEnterEvent(QDragEnterEvent *e)

### `[override virtual protected]` void QWebEngineView::dragLeaveEvent(QDragLeaveEvent *e)

### `[override virtual protected]` void QWebEngineView::dragMoveEvent(QDragMoveEvent *e)

### `[override virtual protected]` void QWebEngineView::dropEvent(QDropEvent *e)

### `[override virtual protected]` bool QWebEngineView::event(QEvent *ev)

### void QWebEngineView::findText(const QString &subString, QWebEnginePage::FindFlags options = QWebEnginePage::FindFlags(), const QWebEngineCallback<bool> &resultCallback = QWebEngineCallback<bool>())

### `[slot]` void QWebEngineView::forward()

### `[override virtual protected]` void QWebEngineView::hideEvent(QHideEvent *event)

### QWebEngineHistory *QWebEngineView::history() const

### void QWebEngineView::load(const QUrl &url)

### void QWebEngineView::load(const QWebEngineHttpRequest &request)

Issues the specified request and loads the response.

This function was introduced in Qt 5.9.

See also load(), setUrl(), url(), urlChanged(), and QUrl::fromUserInput().

### `[signal]` void QWebEngineView::loadFinished(bool)

### `[signal]` void QWebEngineView::loadProgress(int progress)

### `[signal]` void QWebEngineView::loadStarted()

### QWebEnginePage *QWebEngineView::page() const

See also setPage().

### QAction *QWebEngineView::pageAction(QWebEnginePage::WebAction action) const

### `[slot]` void QWebEngineView::reload()

### `[signal]` void QWebEngineView::renderProcessTerminated(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode)

### `[signal]` void QWebEngineView::selectionChanged()

### void QWebEngineView::setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl())

### void QWebEngineView::setHtml(const QString &html, const QUrl &baseUrl = QUrl())

### void QWebEngineView::setPage(QWebEnginePage *page)

See also page().

### QWebEngineSettings *QWebEngineView::settings() const

### `[override virtual protected]` void QWebEngineView::showEvent(QShowEvent *event)

### `[override virtual]` QSize QWebEngineView::sizeHint() const

### `[slot]` void QWebEngineView::stop()

### `[signal]` void QWebEngineView::titleChanged(const QString &title)

### void QWebEngineView::triggerPageAction(QWebEnginePage::WebAction action, bool checked = false)

### `[signal]` void QWebEngineView::urlChanged(const QUrl &)