QWebEngineView Class
The QWebEngineView class provides a widget that is used to view and edit web documents. More...
Header: | #include <QWebEngineView> |
Inherits: | QWidget. |
Properties
|
|
Public Functions
QWebEngineView(QWidget * parent = 0) | |
virtual | ~QWebEngineView() |
void | findText(const QString & subString, QWebEnginePage::FindFlags options = 0) |
void | findText(const QString & subString, QWebEnginePage::FindFlags options, FunctorOrLambda resultCallback) |
bool | hasSelection() const |
QWebEngineHistory * | history() const |
QUrl | iconUrl() const |
void | load(const QUrl & url) |
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 |
- 217 public functions inherited from QWidget
- 31 public functions inherited from QObject
- 13 public functions inherited from QPaintDevice
Public Slots
Signals
void | iconUrlChanged(const QUrl & url) |
void | loadFinished(bool ok) |
void | loadProgress(int progress) |
void | loadStarted() |
void | selectionChanged() |
void | titleChanged(const QString & title) |
void | urlChanged(const QUrl & url) |
Protected Functions
virtual QWebEngineView * | createWindow(QWebEnginePage::WebWindowType type) |
Reimplemented Protected Functions
virtual void | contextMenuEvent(QContextMenuEvent * event) |
virtual bool | event(QEvent * ev) |
- 37 protected functions inherited from QWidget
- 9 protected functions inherited from QObject
- 1 protected function inherited from QPaintDevice
Additional Inherited Members
- 5 static public members inherited from QWidget
- 11 static public members inherited from QObject
- 1 protected slot inherited from QWidget
Detailed Description
The QWebEngineView class provides a widget that is used to view and edit web documents.
QWebEngineView 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 onto QWebEngineView with the load() function. Like all Qt widgets, the show() function must be invoked in order to display QWebEngineView. The snippet below illustrates this:
QWebEngineView *view = new QWebEngineView(parent); view->load(QUrl("http://qt-project.org/")); view->show();
Alternatively, setUrl() can also 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. The loadProgress() signal, on the other hand, is emitted whenever an element of the web view completes loading, such as an embedded image, a script, etc. Finally, the loadFinished() signal is emitted when the view has loaded completely. It's argument - either true
or false
- indicates load success or failure.
The page() function returns a pointer to the web page object. See Elements of QWebEngineView for an explanation of how the web page is related to the view.
The title of an HTML document can be accessed with the title() property. Additionally, a web site may also specify an icon, which can be accessed using the icon() property. If the title or the icon changes, the corresponding titleChanged() and iconChanged() signals will be emitted. The textSizeMultiplier() property can be used to change the overall size of the text displayed in the web view.
If you require a custom context menu, you can implement it by reimplementing contextMenuEvent() and populating your QMenu with the actions obtained from pageAction(). More functionality such as reloading the view, copying selected text to the clipboard, or pasting into the view, is also encapsulated within the QAction objects returned by pageAction(). These actions can be programmatically triggered using triggerPageAction(). Alternatively, the actions can be added to a toolbar or a menu directly. QWebEngineView maintains the state of the returned actions but allows modification of action properties such as text or icon.
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.
Elements of QWebEngineView
QWebEngineView contains a QWebEnginePage, which in turn allows access to the QWebEngineHistory in the page's context.
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().
iconUrl : const QUrl
This property holds the url of the icon associated with the web page currently viewed.
Access functions:
QUrl | iconUrl() const |
See also iconUrlChanged().
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.
Access functions:
qreal | zoomFactor() const |
void | setZoomFactor(qreal factor) |
Member Function Documentation
QWebEngineView::QWebEngineView(QWidget * parent = 0)
Constructs an empty QWebEngineView with parent parent.
See also load().
[virtual]
QWebEngineView::~QWebEngineView()
Destroys the web view.
[slot]
void 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);
See also forward() and pageAction().
[virtual protected]
void QWebEngineView::contextMenuEvent(QContextMenuEvent * event)
Reimplemented from QWidget::contextMenuEvent().
[virtual protected]
QWebEngineView * QWebEngineView::createWindow(QWebEnginePage::WebWindowType type)
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. This might be the result, for example, of a JavaScript request to open a document in a new window.
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 QWebEnginePage::createWindow().
[virtual protected]
bool QWebEngineView::event(QEvent * ev)
Reimplemented from QObject::event().
void QWebEngineView::findText(const QString & subString, QWebEnginePage::FindFlags options = 0)
Finds the specified string, subString, in the page, using the given options.
To clear the selection, just pass an empty string.
See also selectedText() and selectionChanged().
void QWebEngineView::findText(const QString & subString, QWebEnginePage::FindFlags options, FunctorOrLambda resultCallback)
Finds the specified string, subString, in the page, using the given options.
To clear the selection, just pass an empty string.
The resultCallback must take a boolean parameter. It will be called with a value of true if the subString was found; otherwise the callback value will be false.
See also selectedText() and selectionChanged().
[slot]
void 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() and pageAction().
QWebEngineHistory * QWebEngineView::history() const
Returns a pointer to the view's history of navigated web pages.
It is equivalent to
view->page()->history();
[signal]
void QWebEngineView::iconUrlChanged(const QUrl & url)
This signal is emitted whenever the icon url of the view changes.
See also iconUrl().
void QWebEngineView::load(const QUrl & url)
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(), and QUrl::fromUserInput().
[signal]
void QWebEngineView::loadFinished(bool ok)
This signal is emitted when a load of the page is finished. ok will indicate whether the load was successful or any error occurred.
See also loadStarted().
[signal]
void QWebEngineView::loadProgress(int progress)
This signal is emitted every time an element in the web page completes loading and the overall loading progress advances.
This signal tracks the progress of all child frames.
The current value is provided by progress and scales from 0 to 100, which is the default range of QProgressBar.
See also loadStarted() and loadFinished().
[signal]
void QWebEngineView::loadStarted()
This signal is emitted when a new load of the page is started.
See also loadProgress() and loadFinished().
QWebEnginePage * QWebEngineView::page() const
Returns a pointer to the underlying web page.
See also setPage().
QAction * QWebEngineView::pageAction(QWebEnginePage::WebAction action) const
Returns a pointer to a QAction that encapsulates the specified web action action.
[slot]
void QWebEngineView::reload()
Reloads the current document.
See also stop(), pageAction(), and loadStarted().
[signal]
void QWebEngineView::selectionChanged()
This signal is emitted whenever the selection changes.
See also selectedText().
void QWebEngineView::setContent(const QByteArray & data, const QString & mimeType = QString(), const QUrl & baseUrl = QUrl())
Sets the content of the web view to the specified content data. If the mimeType argument is empty it is currently assumed that the content is HTML but in future versions we may introduce auto-detection.
External objects referenced in the content are located relative to baseUrl.
The data is loaded immediately; external objects are loaded asynchronously.
See also load(), setHtml(), and QWebEnginePage::toHtml().
void QWebEngineView::setHtml(const QString & html, const QUrl & baseUrl = QUrl())
Sets the content of the web view to the specified html.
External objects such as stylesheets or images referenced in the HTML document are located relative to baseUrl.
The html is loaded immediately; 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 also be specified by the web server.
This is a convenience function equivalent to setContent(html, "text/html", baseUrl).
Warning: This function works only for HTML, for other mime types (i.e. XHTML, SVG) setContent() should be used instead.
See also load(), setContent(), QWebEnginePage::toHtml(), and QWebEnginePage::setContent().
void QWebEngineView::setPage(QWebEnginePage * page)
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().
QWebEngineSettings * QWebEngineView::settings() const
Returns a pointer to the view/page specific settings object.
It is equivalent to
view->page()->settings();
See also QWebEngineSettings::globalSettings().
[virtual]
QSize QWebEngineView::sizeHint() const
Reimplemented from QWidget::sizeHint().
[slot]
void QWebEngineView::stop()
Convenience slot that stops loading the document.
It is equivalent to
view->page()->triggerAction(QWebEnginePage::Stop);
See also reload(), pageAction(), and loadFinished().
[signal]
void QWebEngineView::titleChanged(const QString & title)
This signal is emitted whenever the title of the main frame changes.
See also title().
void QWebEngineView::triggerPageAction(QWebEnginePage::WebAction action, bool checked = false)
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().
[signal]
void QWebEngineView::urlChanged(const QUrl & url)
This signal is emitted when the url of the view changes.
© 2015 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.