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 |
Inherits: | QWidget |
Properties
|
|
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 |
- 225 public functions inherited from QWidget
- 34 public functions inherited from QObject
- 14 public functions inherited from QPaintDevice
Public Slots
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 |
- 35 protected functions inherited from QWidget
- 9 protected functions inherited from QObject
- 1 protected function inherited from QPaintDevice
Additional Inherited Members
- 1 public variable inherited from QWidget
- 1 public variable inherited from QObject
- 7 static public members inherited from QWidget
- 10 static public members inherited from QObject
- 1 protected slot inherited from QWidget
- 2 protected variables inherited from QObject
- 1 protected type inherited from QPaintDevice
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)
Reimplemented from QWidget::contextMenuEvent().
[virtual protected]
QWebEngineView *QWebEngineView::createWindow(QWebEnginePage::WebWindowType type)
[override virtual protected]
void QWebEngineView::dragEnterEvent(QDragEnterEvent *e)
Reimplemented from QWidget::dragEnterEvent().
[override virtual protected]
void QWebEngineView::dragLeaveEvent(QDragLeaveEvent *e)
Reimplemented from QWidget::dragLeaveEvent().
[override virtual protected]
void QWebEngineView::dragMoveEvent(QDragMoveEvent *e)
Reimplemented from QWidget::dragMoveEvent().
[override virtual protected]
void QWebEngineView::dropEvent(QDropEvent *e)
Reimplemented from QWidget::dropEvent().
[override virtual protected]
bool QWebEngineView::event(QEvent *ev)
Reimplemented from QWidget::event().
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)
Reimplemented from QWidget::hideEvent().
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)
Reimplemented from QWidget::showEvent().
[override virtual]
QSize QWebEngineView::sizeHint() const
Reimplemented from QWidget::sizeHint().