WebEngineView QML 类型

A WebEngineView renders web content within a QML application. 更多...

导入语句: import QtWebEngine 1.8
Since: QtWebEngine 1.0
继承:

Item

特性

信号

方法

详细描述

WebEngineView type enables QML applications to render regions of dynamic web content. It may share the screen with other QML types, such as a TabView, or fill the screen, as specified within the QML application.

初始化 Web 引擎

For the web engine view to be rendered, the web engine must be initialized by using QtWebEngine::initialize in the application main source file, as illustrated by the following code snippet:

int main(int argc, char *argv[])
{
    QCoreApplication::setOrganizationName("QtExamples");
    QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
    QGuiApplication app(argc, argv);
    QtWebEngine::initialize();
    QQmlApplicationEngine engine;
    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
    return app.exec();
}
						

加载网页

An application can load pages into the WebEngineView , using either the url property or the loadHtml method and navigate within the view's session history. The GET method is always used to load URLs.

The history is represented by a WebEngineHistory data model that is held by the navigationHistory 特性。

The following sample QML application loads a web page using the url 特性:

import QtQuick 2.0
import QtQuick.Window 2.0
import QtWebEngine 1.0
Window {
    width: 1024
    height: 750
    visible: true
    WebEngineView {
        anchors.fill: parent
        url: "https://www.qt.io"
    }
}
						

loading property holds whether an HTML page is currently loading. The loadingChanged() signal is emitted when loading the page begins, ends, or fails.

HTML 页面标题可以被访问采用 title property. Additionally, a web page may specify an icon, which can be accessed using the icon property. The zoomFactor property enables zooming the contents of the web page by a scale factor.

If a certificate error is raised while loading a web page, the certificateError() signal is emitted. Certificate errors are handled by using the methods of the WebEngineCertificateError 类型。

交互

By default, links to different pages load within the same WebEngineView object, but web sites may request them to be opened as a new tab, window, or dialog. The newViewRequested() signal is emitted when a request to load the page in a separate web engine view is issued. The NewViewDestination property describes how the new view should be opened. In addition, the WebEngineNewViewRequest utility type can be used to load web pages in separate web engine views.

findText() method can be used to search for a string on a web page, using the options described by FindFlags .

setActiveFocusOnPress() method can be used to create a UI element that should not get focus on press. This can be useful in a hybrid UI.

focusOnNavigationEnabled setting can be used to make the view automatically receive focus when a navigation operation occurs (like loading or reloading a page or navigating through history).

linkHovered() signal is emitted when a mouse pointer passes over a link and thus corresponds to the mouseover DOM event.

Actions, such as selecting and editing content, can be performed on a web page by using the triggerWebAction() method. The available actions are described by the WebAction 特性。

backgroundColorChanged() signal is emitted when the web page background color changes.

用户脚本

During the loading of a page, so called 用户脚本 can be injected in the JavaScript engine at different points. The script objects attached to the web engine view are held by the userScripts property and injected by using the WebEngineScript type. Scripts can also be run by using the runJavaScript() method in the same world as other scripts that are part of the loaded site.

webChannel property can be used to expose a WebChannel instance in the JavaScript context of the page it is rendering as qt.webChannelTransport .

全屏模式

A web page can request through the JavaScript API to be loaded in fullscreen mode. The fullScreenRequested() signal is emitted when the web page issues the request. The FullScreenRequest utility type can be used to toggle fullscreen requests. The fullScreenCancelled method can be used to notify the browser engine when the windowing system forces the application to leave fullscreen mode.

Profiles

Web engine views can be isolated from each other by using the WebEngineProfile type. A profile contains settings, scripts, and the list of visited links shared by all views that belong to the profile. For example, a dedicated profile could be created for a 隐私浏览 mode. The current profile for the view is held by the profile property and the current settings are held by the settings property. The settings are specified by using the WebEngineSettings 类型。

平台特征

Web pages can request access to platform features, such as geolocation or audio and video capture devices. The featurePermissionRequested() signal is emitted when a web page requests to make use of a resource. The supported platform features are described by the Feature property. If users grant the permission, the grantFeaturePermission() method is used to set it to granted .

渲染到 OpenGL 表面

当使用 QQuickRenderControl to render a Qt Quick user interface to an OpenGL surface, the WebEngineView type is not rendered correctly. The web engine view attempts to use a global OpenGL context created by QtWebEngine::initialize , but there is no public API for accessing that context in order to share it with the QQuickRenderControl context.

To have the web engine view rendered correctly, it is possible to manually create a new offscreen context that is shared with the QQuickRenderControl and to call the non-public function qt_gl_set_global_share_context() , rather than calling initialize() 。若 initialize() is called after setting a global context, it will do nothing.

特性文档编制

ErrorDomain : enumeration

Describes various high-level error types:

常量 描述
WebEngineView.NoErrorDomain
WebEngineView.InternalErrorDomain Content fails to be interpreted by Qt WebEngine.
WebEngineView.ConnectionErrorDomain Error results from faulty network connection.
WebEngineView.CertificateErrorDomain Error related to the SSL/TLS certificate.
WebEngineView.HttpErrorDomain Error related to the HTTP connection.
WebEngineView.FtpErrorDomain Error related to the FTP connection.
WebEngineView.DnsErrorDomain Error related to the DNS connection.

Feature : enumeration

Describes the platform feature access categories that the user may be asked to grant or deny access to:

常量 描述
WebEngineView.Geolocation Location hardware or service.
WebEngineView.MediaAudioCapture Audio capture devices, such as microphones.
WebEngineView.MediaVideoCapture Video devices, such as cameras.
WebEngineView.MediaAudioVideoCapture Both audio and video capture devices.
DesktopVideoCapture Video output capture, that is, the capture of the user's display. (Added in Qt 5.10)
DesktopAudioVideoCapture Both audio and video output capture. (Added in Qt 5.10)

另请参阅 featurePermissionRequested() and grantFeaturePermission() .


FindFlags : enumeration

Describes the options available to the findText() function. The options can be OR-ed together from the following list:

常量 描述
WebEngineView.FindBackward 向后搜索,而不是向前。
WebEngineView.FindFlags FindCaseSensitively By default findText() works case insensitive. Specifying this option changes the behavior to a case sensitive find operation.

另请参阅 findText() .


JavaScriptConsoleMessageLevel : enumeration

Indicates the severity of a JavaScript console message:

常量 描述
WebEngineView.InfoMessageLevel Message is purely informative and can safely be ignored.
WebEngineView.WarningMessageLevel Message indicates there might be a problem that may need attention.
WebEngineView.ErrorMessageLevel Message indicates there has been an error.

LoadStatus : enumeration

Reflects a page's load status:

常量 描述
WebEngineView.LoadStartedStatus Page is currently loading.
WebEngineView.LoadStoppedStatus Loading the page was stopped by the stop() method or by the loader code or network stack in Chromium.
WebEngineView.LoadSucceededStatus Page has successfully loaded, and is not currently loading.
WebEngineView.LoadFailedStatus Page has failed to load, and is not currently loading.

NewViewDestination : enumeration

Describes how to open a new view:

常量 描述
WebEngineView.NewViewInWindow In a separate Window.
WebEngineView.NewViewInTab In a tab of the same window.
WebEngineView.NewViewInDialog In a Window without a tab bar, toolbar, or URL bar.
WebEngineView.NewViewInBackgroundTab In a tab of the same window, without hiding the currently visible web engine view.

另请参阅 WebEngineNewViewRequest.destination .


PrintedPageOrientation : enumeration

Describes the orientation of a PDF document that gets created from the WebEngineView 's contents. The enumeration values are mapped from and must match QPageLayout::Orientation .

常量 描述
WebEngineView.Portrait The document will be created using portrait orientation.
WebEngineView.Landscape The document will be created using landscape orientation.

This property was introduced in QtWebEngine 1.3.

另请参阅 WebEngineView::printToPdf() .


PrintedPageSizeId : enumeration

This enum type lists the available page sizes as defined in the Postscript PPD standard.

The enumeration values are mapped from and must match QPageSize::PageSizeId . They are also duplicated in QPagedPaintDevice and QPrinter .

The defined sizes are:

常量 描述
WebEngineView.A0 841 x 1189 mm
WebEngineView.A1 594 x 841 mm
WebEngineView.A2 420 x 594 mm
WebEngineView.A3 297 x 420 mm
WebEngineView.A4 210 x 297 mm, 8.26 x 11.69 inches
WebEngineView.A5 148 x 210 mm
WebEngineView.A6 105 x 148 mm
WebEngineView.A7 74 x 105 mm
WebEngineView.A8 52 x 74 mm
WebEngineView.A9 37 x 52 mm
WebEngineView.B0 1000 x 1414 mm
WebEngineView.B1 707 x 1000 mm
WebEngineView.B2 500 x 707 mm
WebEngineView.B3 353 x 500 mm
WebEngineView.B4 250 x 353 mm
WebEngineView.B5 176 x 250 mm, 6.93 x 9.84 inches
WebEngineView.B6 125 x 176 mm
WebEngineView.B7 88 x 125 mm
WebEngineView.B8 62 x 88 mm
WebEngineView.B9 44 x 62 mm
WebEngineView.B10 31 x 44 mm
WebEngineView.C5E 163 x 229 mm
WebEngineView.Comm10E 105 x 241 mm, U.S. Common 10 Envelope
WebEngineView.DLE 110 x 220 mm
WebEngineView.Executive 7.5 x 10 inches, 190.5 x 254 mm
WebEngineView.Folio 210 x 330 mm
WebEngineView.Ledger 431.8 x 279.4 mm
WebEngineView.Legal 8.5 x 14 inches, 215.9 x 355.6 mm
WebEngineView.Letter 8.5 x 11 inches, 215.9 x 279.4 mm
WebEngineView.Tabloid 279.4 x 431.8 mm
WebEngineView.Custom Unknown, or a user defined size.
WebEngineView.A10
WebEngineView.A3Extra
WebEngineView.A4Extra
WebEngineView.A4Plus
WebEngineView.A4Small
WebEngineView.A5Extra
WebEngineView.B5Extra
WebEngineView.JisB0
WebEngineView.JisB1
WebEngineView.JisB2
WebEngineView.JisB3
WebEngineView.JisB4
WebEngineView.JisB5
WebEngineView.JisB6
WebEngineView.JisB7
WebEngineView.JisB8
WebEngineView.JisB9
WebEngineView.JisB10
WebEngineView.AnsiA = Letter
WebEngineView.AnsiB = Ledger
WebEngineView.AnsiC
WebEngineView.AnsiD
WebEngineView.AnsiE
WebEngineView.LegalExtra
WebEngineView.LetterExtra
WebEngineView.LetterPlus
WebEngineView.LetterSmall
WebEngineView.TabloidExtra
WebEngineView.ArchA
WebEngineView.ArchB
WebEngineView.ArchC
WebEngineView.ArchD
WebEngineView.ArchE
WebEngineView.Imperial7x9
WebEngineView.Imperial8x10
WebEngineView.Imperial9x11
WebEngineView.Imperial9x12
WebEngineView.Imperial10x11
WebEngineView.Imperial10x13
WebEngineView.Imperial10x14
WebEngineView.Imperial12x11
WebEngineView.Imperial15x11
WebEngineView.ExecutiveStandard
WebEngineView.Note
WebEngineView.Quarto
WebEngineView.Statement
WebEngineView.SuperA
WebEngineView.SuperB
WebEngineView.Postcard
WebEngineView.DoublePostcard
WebEngineView.Prc16K
WebEngineView.Prc32K
WebEngineView.Prc32KBig
WebEngineView.FanFoldUS
WebEngineView.FanFoldGerman
WebEngineView.FanFoldGermanLegal
WebEngineView.EnvelopeB4
WebEngineView.EnvelopeB5
WebEngineView.EnvelopeB6
WebEngineView.EnvelopeC0
WebEngineView.EnvelopeC1
WebEngineView.EnvelopeC2
WebEngineView.EnvelopeC3
WebEngineView.EnvelopeC4
WebEngineView.EnvelopeC5 = C5E
WebEngineView.EnvelopeC6
WebEngineView.EnvelopeC65
WebEngineView.EnvelopeC7
WebEngineView.EnvelopeDL = DLE
WebEngineView.Envelope9
WebEngineView.Envelope10 = Comm10E
WebEngineView.Envelope11
WebEngineView.Envelope12
WebEngineView.Envelope14
WebEngineView.EnvelopeMonarch
WebEngineView.EnvelopePersonal
WebEngineView.EnvelopeChou3
WebEngineView.EnvelopeChou4
WebEngineView.EnvelopeInvite
WebEngineView.EnvelopeItalian
WebEngineView.EnvelopeKaku2
WebEngineView.EnvelopeKaku3
WebEngineView.EnvelopePrc1
WebEngineView.EnvelopePrc2
WebEngineView.EnvelopePrc3
WebEngineView.EnvelopePrc4
WebEngineView.EnvelopePrc5
WebEngineView.EnvelopePrc6
WebEngineView.EnvelopePrc7
WebEngineView.EnvelopePrc8
WebEngineView.EnvelopePrc9
WebEngineView.EnvelopePrc10
WebEngineView.EnvelopeYou4
WebEngineView.LastPageSize = EnvelopeYou4

This property was introduced in QtWebEngine 1.3.

另请参阅 WebEngineView::printToPdf() .


RenderProcessTerminationStatus : enumeration

Describes the status with which the render process terminated:

常量 描述
WebEngineView.NormalTerminationStatus 渲染进程正常终止。
WebEngineView.AbnormalTerminationStatus The render process terminated with a non-zero exit status.
WebEngineView.CrashedTerminationStatus 渲染进程崩溃 (例如:由于分段故障)。
WebEngineView.KilledTerminationStatus 渲染进程被杀除,例如被 SIGKILL 或被任务管理器杀除。

This property was introduced in QtWebEngine 1.2.


WebAction : enumeration

Describes the types of action that can be performed on a web page:

常量 描述
WebEngineView.NoWebAction 没有动作被触发。
WebEngineView.Back 在导航链接历史中后退导航。
WebEngineView.Forward 在导航链接历史中前进导航。
WebEngineView.Stop 停止加载当前页面。
WebEngineView.Reload 重新加载当前页面。
WebEngineView.ReloadAndBypassCache 重新加载当前页面,但不使用任何本地缓存。
WebEngineView.Cut 把目前选中内容剪切到剪贴板。
WebEngineView.Copy 把目前选中内容拷贝到剪贴板。
WebEngineView.Paste 从剪贴板粘贴内容。
WebEngineView.Undo 撤消上一编辑动作。
WebEngineView.Redo 重做上一编辑动作。
WebEngineView.SelectAll 选择所有内容。仅当页面内容被聚焦时此动作才启用。聚焦可以被强制通过 JavaScript window.focus() 调用,或 focusOnNavigationEnabled 设置应该被启用以获得自动聚焦。
WebEngineView.PasteAndMatchStyle 采用当前样式从剪贴板粘贴内容。
WebEngineView.OpenLinkInThisWindow 在当前窗口中打开当前链接。(在 Qt 5.6 添加)
WebEngineView.OpenLinkInNewWindow Open the current link in a new window. Requires a handler for the newViewRequested() signal. (Added in Qt 5.6)
WebEngineView.OpenLinkInNewTab Open the current link in a new tab. Requires a handler for the newViewRequested() signal. (Added in Qt 5.6)
WebEngineView.CopyLinkToClipboard 把当前链接拷贝到剪贴板。(在 Qt 5.6 添加)
WebEngineView.CopyImageToClipboard 把被点击图像拷贝到剪贴板。(在 Qt 5.6 添加)
WebEngineView.CopyImageUrlToClipboard 把被点击图像的 URL 拷贝到剪贴板。(在 Qt 5.6 添加)
WebEngineView.CopyMediaUrlToClipboard 把悬停音频或视频的 URL 拷贝到剪贴板。(在 Qt 5.6 添加)
WebEngineView.ToggleMediaControls Toggle between showing and hiding the controls for the hovered audio or video element. (Added in Qt 5.6)
WebEngineView.ToggleMediaLoop Toggle whether the hovered audio or video should loop on completetion or not. (Added in Qt 5.6)
WebEngineView.ToggleMediaPlayPause Toggle the play/pause state of the hovered audio or video element. (Added in Qt 5.6)
WebEngineView.ToggleMediaMute 静音或取消静音悬停的音频或视频元素。(在 Qt 5.6 添加)
WebEngineView.DownloadLinkToDisk Download the current link to the disk. To implement download actions, connect to the WebEngineProfile.downloadRequested signal. (Added in Qt 5.6)
WebEngineView.DownloadImageToDisk Download the highlighted image to the disk. (Added in Qt 5.6)
WebEngineView.DownloadMediaToDisk Download the hovered audio or video to the disk. (Added in Qt 5.6)
WebEngineView.InspectElement Trigger any attached Web Inspector to inspect the highlighed element. (Added in Qt 5.6)
WebEngineView.ExitFullScreen 退出全屏模式。(在 Qt 5.6 添加)
WebEngineView.SavePage Save the current web page to disk. (Added in Qt 5.7)
WebEngineView.ViewSource Show the source of the current page in a new tab. Requires a handler for the newViewRequested() signal. (Added in Qt 5.8)
WebEngineView.ToggleBold Toggles boldness for the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.ToggleItalic Toggles italics for the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.ToggleUnderline Toggles underlining of the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.ToggleStrikethrough Toggles striking through the selection or at the cursor position. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.AlignLeft Aligns the lines containing the selection or the cursor to the left. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.AlignCenter Aligns the lines containing the selection or the cursor at the center. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.AlignRight Aligns the lines containing the selection or the cursor to the right. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.AlignJustified Stretches the lines containing the selection or the cursor so that each line has equal width. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.Indent 缩进包含选定或光标的行。要求 contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.Outdent 伸出包含选定或光标的行。要求 contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.InsertOrderedList Inserts an ordered list at the current cursor position, deleting the current selection. Requires contenteditable="true" 。(在 Qt 5.10 添加)
WebEngineView.InsertUnorderedList Inserts an unordered list at the current cursor position, deleting the current selection. Requires contenteditable="true" 。(在 Qt 5.10 添加)

This property was introduced in QtWebEngine 1.2.


activeFocusOnPress : bool

Specifies whether the view should gain active focus when pressed. The default value is true .

This property was introduced in QtWebEngine 1.2.


audioMuted : bool

The state of whether the current page audio is muted.

This property was introduced in QtWebEngine 1.3.

另请参阅 recentlyAudible .


backgroundColor : bool

Changes the color of the WebEngineView 's background, behind the document's body. Can be set to "transparent" or to a translucent color to see through the document or to match the web content in a hybrid app to prevent the white flashes that may appear during loading.

默认值为白色。

This property was introduced in QtWebEngine 1.2.


[read-only] canGoBack : bool

返回 true if there are prior session history entries, false 否则。


[read-only] canGoForward : bool

返回 true if there are subsequent session history entries, false 否则。


contentsSize : size

Size of the page contents.

This property was introduced in QtWebEngine 1.3.


devToolsView : WebEngineView

The view currently hosting the developer tools for this view. Setting it to a new view will navigate that view to an internal URL with the developer tools, and bind it to this view.

This property was introduced in QtWebEngine 1.7.

另请参阅 inspectedView .


[read-only] icon : url

An internal URL for accessing the currently displayed web site icon, also known as favicon or shortcut icon. The icon is already downloaded and stored by the Qt WebEngine's favicon manager. This read-only URL corresponds to the image used within a mobile browser application to represent a bookmarked page on the device's home screen.

The following snippet uses the icon property to build an Image component:

Image {
    id: appIcon
    sourceSize: Qt.size(32, 32)
    source: webView.icon != "" ? webView.icon : "fallbackFavicon.png";
    // ...
}
								

Specifying the sourceSize 特性为 Image element informs the Qt WebEngine's favicon provider about the requested size. The favicon provider tries to find the best fit among the web page candidate icons. If sourceSize property is not specified, the provider provides the icon with the largest resolution.


inspectedView : WebEngineView

The view this view is currently inspecting, if any. Setting it will navigate to an internal URL with the developer tools of the view set.

It is recommended to unset this property when developer tools are not visible; otherwise some debug information may appear in the inspected WebEngineView .

This property was introduced in QtWebEngine 1.7.

另请参阅 devToolsView .


[read-only] isFullScreen : bool

返回 true if the web view is in fullscreen mode, false 否则。

This property was introduced in QtWebEngine 1.1.

另请参阅 fullScreenRequested() and fullScreenCancelled() .


[read-only] loadProgress : int

The amount of data from the page that has been loaded, expressed as an integer percentage in the range from 0 to 100 .


[read-only] loading : bool

返回 true if the HTML page is currently loading, false 否则。


The navigation history of the current view.

This property was introduced in QtWebEngine 1.1.

另请参阅 WebEngineHistory .


The current profile used for the view.

This property was introduced in QtWebEngine 1.1.

另请参阅 WebEngineProfile .


[read-only] recentlyAudible : bool

Returns the current page's audible state (audio was recently played, or not).

This property was introduced in QtWebEngine 1.3.

另请参阅 audioMuted and recentlyAudibleChanged .


scrollPosition : point

Scroll position of the page contents.

This property was introduced in QtWebEngine 1.3.


[read-only] settings : WebEngineSettings

Settings used by this view.

This property was introduced in QtWebEngine 1.1.

另请参阅 WebEngineSettings .


[read-only] title : string

The title of the currently displayed HTML page. This is a read-only value that reflects the contents of the <title> tag.


url : url

The location of the currently displayed HTML page. This writable property offers the main interface to load a page into a web view. It functions the same as the window.location DOM property.

另请参阅 loadHtml() .


[read-only] userScripts : list < WebEngineScript >

List of script objects attached to the view.

This property was introduced in QtWebEngine 1.1.

另请参阅 WebEngineScript .


webChannel : QQmlWebChannel

The web channel instance used by this view. This channel is automatically using the internal QtWebEngine transport mechanism over Chromium IPC, and exposed in the javascript context of the page it is rendering as qt.webChannelTransport . This transport object is used when instantiating the JavaScript counterpart of QWebChannel 使用 Qt WebChannel JavaScript API .

注意: The view does not take ownership for an assigned webChannel object.

This property was introduced in QtWebEngine 1.1.


webChannelWorld : int

JavaScript world that the web channel instance used by this view is installed in. The world must be a number between 0 and 256 .

This property was introduced in QtWebEngine 1.3.


zoomFactor : real

Zoom factor for the view. Valid values are within the range from 0.25 to 5.0 。默认因子为 1.0 .

This property was introduced in QtWebEngine 1.1.


信号文档编制

activeFocusOnPressChanged ( bool activeFocusOnPress )

This signal is emitted when the value of activeFocusOnPress changes. It specifies whether the view should gain active focus when pressed.

This signal was introduced in QtWebEngine 1.2.

另请参阅 activeFocusOnPress and setActiveFocusOnPress() .


audioMutedChanged ( bool muted )

This signal is emitted when the value of muted changes. The value is specified using the audioMuted 特性。

注意: Not to be confused with a specific HTML5 audio / video element being muted.

This signal was introduced in QtWebEngine 1.3.

另请参阅 audioMuted and recentlyAudibleChanged .


authenticationDialogRequested ( AuthenticationDialogRequest request )

This signal is emitted when an authentication dialog is requested.

request can be handled by using the methods of the AuthenticationDialogRequest 类型。

注意: Signal handlers need to call request.accepted = true to prevent a default dialog from showing up. Make sure to call either AuthenticationDialogRequest::dialogAccept() or AuthenticationDialogRequest::dialogReject() afterwards.

This signal was introduced in QtWebEngine 1.4.


backgroundColorChanged ()

This signal is emitted when the web engine view background color changes.

This signal was introduced in QtWebEngine 1.2.


certificateError ( WebEngineCertificateError error )

This signal is emitted when an invalid certificate error, error , is raised while loading a given request.

The certificate error can be handled by using the methods of the WebEngineCertificateError 类型。

This signal was introduced in QtWebEngine 1.1.


colorDialogRequested ( ColorDialogRequest request )

This signal is emitted when a color picker dialog is requested.

request can be handled by using the methods of the ColorDialogRequest 类型。

注意: Signal handlers need to call request.accepted = true to prevent a default dialog from showing up. Make sure to call either ColorDialogRequest::dialogAccept() or ColorDialogRequest::dialogReject() afterwards.

This signal was introduced in QtWebEngine 1.4.


contextMenuRequested ( ContextMenuRequest request )

This signal is emitted when a context menu is requested.

request can be handled by using the properties of the ContextMenuRequest 类型。

注意: Signal handlers need to call request.accepted = true to prevent a default context menu from showing up.

This signal was introduced in QtWebEngine 1.4.


featurePermissionRequested ( url securityOrigin , Feature feature )

此信号被发射当网站被标识,通过 securityOrigin requests to make use of the resource or device identified by feature .

This signal was introduced in QtWebEngine 1.1.

另请参阅 grantFeaturePermission() .


fileDialogRequested ( FileDialogRequest request )

This signal is emitted when a file picker dialog is requested.

request can be handled by using the methods of the FileDialogRequest 类型。

注意: Signal handlers need to call request.accepted = true to prevent a default dialog from showing up. Make sure to call either FileDialogRequest::dialogAccept() or FileDialogRequest::dialogReject() afterwards.

This signal was introduced in QtWebEngine 1.4.


fullScreenRequested ( FullScreenRequest request )

This signal is emitted when the web page issues the request for fullscreen mode through the JavaScript API.

This signal was introduced in QtWebEngine 1.1.

另请参阅 isFullScreen .


geometryChangeRequested ( rect geometry , rect frameGeometry )

此信号被发射每当文档希望把页面位置和大小更改为 frameGeometry 。这会发生,例如透过 JavaScript。

While frameGeometry includes, geometry excludes the size of frame margins.

注意: Geometry related properties of QML Window expect a size excluding the window decoration. You have to use geometry 以正确处理此信号。

onGeometryChangeRequested: {
    window.x = geometry.x
    window.y = geometry.y
    window.width = geometry.width
    window.height = geometry.height
}
								

This signal was introduced in QtWebEngine 1.7.


javaScriptConsoleMessage ( JavaScriptConsoleMessageLevel level , string message , int lineNumber , string sourceID )

This signal is emitted when a JavaScript program tries to print a message to the web browser's console.

For example, in case of evaluation errors the source URL may be provided in sourceID as well as the lineNumber .

level indicates the severity of the event that triggered the message, that is, whether it was triggered by an error or a less severe event.

If no handler is specified, the view will log the messages into a js 日志类别 .

另请参阅 控制台日志 .


javaScriptDialogRequested ( JavaScriptDialogRequest request )

This signal is emitted when a JavaScript dialog is requested.

request can be handled by using the methods of the JavaScriptDialogRequest 类型。

注意: Signal handlers need to call request.accepted = true to prevent a default dialog from showing up. Make sure to call either JavaScriptDialogRequest::dialogAccept() or JavaScriptDialogRequest::dialogReject() afterwards.

This signal was introduced in QtWebEngine 1.4.


linkHovered ( url hoveredUrl )

Within a mouse-driven interface, this signal is emitted when a mouse pointer passes over a link, corresponding to the mouseover DOM event. This event may also occur in touch interfaces for mouseover events that are not cancelled with preventDefault() . hoveredUrl provides the link's location.


loadingChanged ( WebEngineLoadRequest loadRequest )

This signal is emitted when a page load begins, ends, or fails.

When handling the signal with onLoadingChanged , various read-only parameters are available on the WebEngineLoadRequest specified by loadRequest .

另请参阅 loading , LoadStatus ,和 ErrorDomain .


This signal is emitted when the navigation request request is issued.


newViewRequested ( WebEngineNewViewRequest request )

此信号被发射当 request is issued to load a page in a separate web engine view. This can either be because the current page requested it explicitly through a JavaScript call to window.open , or because the user clicked on a link while holding Shift, Ctrl, or a built-in combination that triggers the page to open in a new window.

If this signal is not handled, the requested load will fail.

An example implementation:

QtObject {
    id: windowParent
    // Create the initial browsing windows and open the startup page.
    Component.onCompleted: {
        var firstWindow = windowComponent.createObject(windowParent);
        firstWindow.webView.loadHtml('<input type="button" value="Click!" onclick="window.open("http://qt.io")">');
    }
    property Component windowComponent: Window {
        // Destroy on close to release the Window's QML resources.
        // Because it was created with a parent, it won't be garbage-collected.
        onClosing: destroy()
        visible: true
        property WebEngineView webView: webView_
        WebEngineView {
            id: webView_
            anchors.fill: parent
            // Handle the signal. Dynamically create the window and
            // use its WebEngineView as the destination of our request.
            onNewViewRequested: function(request) {
                var newWindow = windowComponent.createObject(windowParent);
                request.openIn(newWindow.webView);
            }
        }
    }
}
								

This signal was introduced in QtWebEngine 1.1.

另请参阅 NewViewDestination and WebEngine Quick 纳米浏览器 .


pdfPrintingFinished ( string filePath , bool success )

此信号被发射当把网页打印成 PDF 文件已完成时。 filePath will contain the path the file was requested to be created at, and success will be true if the file was successfully created and false 否则。

This signal was introduced in QtWebEngine 1.5.

另请参阅 printToPdf() .


printRequest ()

此信号被发射当 JavaScript window.print() 方法被调用。通常,信号处理程序可以简单调用 printToPdf() .

This signal was introduced in QtWebEngine 1.8.

另请参阅 printToPdf .


quotaRequested ( QuotaRequest request )

This signal is emitted when the web page issues a request for a larger persistent storage than the application's current allocation in File System API. The default quota is 0 bytes.

This signal was introduced in QtWebEngine 1.7.

另请参阅 QuotaRequest .


recentlyAudibleChanged ( bool recentlyAudible )

This signal is emitted when the page's audible state, specified by recentlyAudible , is changed, due to audio being played or stopped.

注意: The signal is also emitted when the audioMuted property changes. Also if the audio is paused, this signal is emitted with an approximate two-second delay , from the moment the audio is paused.

This signal is also emitted for Flash plugin audio.

If a web page contains two videos that are started in sequence, this signal gets emitted only once, for the first video to generate sound. After both videos are stopped, the signal is emitted upon the last sound generated. This means that the signal is emitted both when any kind of sound is generated and when everything is completely silent within a web page, regardless of the number of audio streams.

Spurious signal emissions might also happen. For example, when sound is stopped, this signal gets emitted first with a value of true , and then with a value of false . Further, when audio starts playing, the signal is emitted twice with a value of true .

This signal was introduced in QtWebEngine 1.3.

另请参阅 recentlyAudible .


registerProtocolHandlerRequested ( RegisterProtocolHandlerRequest request )

This signal is emitted when the web page tries to register a custom protocol by issuing a registerProtocolHandler request .

This signal was introduced in QtWebEngine 1.7.

另请参阅 RegisterProtocolHandlerRequest .


renderProcessTerminated ( RenderProcessTerminationStatus terminationStatus , int exitCode )

此信号被发射当渲染进程采用非零退出状态被终止时。 terminationStatus 是进程的终止状态,且 exitCode 是进程终止的状态码。

This signal was introduced in QtWebEngine 1.2.

另请参阅 RenderProcessTerminationStatus .


wasRecentlyAudibleChanged ( bool wasRecentlyAudible )

This signal is emitted when the page's audible state, specified by wasRecentlyAudible , is changed, due to audio being played or stopped.

注意: The signal is also emitted when calling the setAudioMuted method. Also if the audio is paused, this signal is emitted with an approximate 2 second delay , from the moment the audio is paused.

This signal was introduced in QtWebEngine 1.3.


windowCloseRequested ()

此信号被发射每当页面请求关闭 Web 浏览器窗口时,例如透过 JavaScript window.close() 调用。

This signal was introduced in QtWebEngine 1.2.


方法文档编制

WebEngineAction action ( WebAction action )

返回 WebEngineAction 为指定 WebAction action . WebEngineView also takes care of implementing the action, so that upon triggering the corresponding action is performed on the view.

var copyAction = webEngineView.action(WebEngineView.Copy);
								

This method was introduced in Qt 5.12.

另请参阅 WebEngineAction .


void findText ( string subString )

查找指定字符串, subString , in the page.

To clear the search highlight, just pass an empty string.

This method was introduced in QtWebEngine 1.1.


void findText ( string subString , FindFlags options )

查找指定字符串, subString , in the page, using the given options .

To clear the search highlight, just pass an empty string.

findText("Qt", WebEngineView.FindBackward | WebEngineView.FindCaseSensitively);
								

This method was introduced in QtWebEngine 1.1.


void findText ( string subString , FindFlags options , variant resultCallback )

查找指定字符串, subString , in the page, using the given options .

To clear the search highlight, just pass an empty string.

resultCallback must take an integer parameter. It will be called with the number of found occurrences of the subString .

findText("Qt", WebEngineView.FindCaseSensitively, function(matchCount) {
    if (matchCount > 0)
        console.log("'Qt' tokens found:", matchCount);
});
								

This method was introduced in QtWebEngine 1.1.


void fullScreenCancelled ()

Immediately sets isFullScreen property to false . It can be used to notify the browser engine when the windowing system forces the application to leave fullscreen mode.

ApplicationWindow {
    onVisibilityChanged: {
        if (webEngineView.isFullScreen && visibility != Window.FullScreen)
            webEngineView.fullScreenCancelled()
    }
    WebEngineView {
        id: webEngineView
        // ...
    }
}
								

This method was introduced in QtWebEngine 1.1.

另请参阅 isFullScreen and fullScreenRequested() .


void goBack ()

Go backward within the browser's session history, if possible. This function is equivalent to the window.history.back() DOM method.

另请参阅 canGoBack .


void goBackOrForward ( int offset )

offset is positive, goes forward the specified number of offset pages in the current session history. If offset is negative, it goes back. If the offset is invalid, the page is not changed.

This method was introduced in QtWebEngine 1.1.

另请参阅 goBack() and goForward() .


void goForward ()

Go forward within the browser's session history, if possible. This function is equivalent to the window.history.forward() DOM method.


void grantFeaturePermission ( url securityOrigin , Feature feature , bool granted )

Sets or unsets the permission, depending on granted , for the web site identified by securityOrigin to use feature .

This method was introduced in QtWebEngine 1.1.

另请参阅 featurePermissionRequested() .


void loadHtml ( string html , url baseUrl )

加载指定 html as the content of the web view.

This method offers a lower-level alternative to the url property, which references HTML pages via URL.

External objects, such as stylesheets or images referenced in the HTML document, should be located relative to baseUrl . For external objects to be loaded, baseUrl cannot be empty. For example, if html is retrieved from http://www.example.com/documents/overview.html , which is the base URL, then an image referenced with the relative URL, diagram.png , should be at http://www.example.com/documents/diagram.png .

另请参阅 url .


void printToPdf (const string filePath , PrintedPageSizeId pageSizeId , PrintedPageOrientation orientation )

Prints the WebEngineView 's current content to a PDF document and stores it under filePath . The document's size will be determined by the value of pageSizeId and its orientation will be determined using orientation .

This method issues an asynchronous request for printing the web page into a PDF and returns immediately. To be informed about the result of the request, connect to the signal pdfPrintingFinished() .

If you leave out pageSizeId , it defaults to A4 . If you leave out orientation , it defaults to Portrait .

This method was introduced in QtWebEngine 1.3.

另请参阅 pdfPrintingFinished() .


void printToPdf ( variant resultCallback , PrintedPageSizeId pageSizeId , PrintedPageOrientation orientation )

Prints the WebEngineView 's current content to a PDF document and returns it in a byte array. The document's size will be determined by the value of pageSizeId and its orientation will be determined using orientation .

resultCallback must take a string parameter. This string will contain the document's data upon successful printing and an empty string otherwise.

If you leave out pageSizeId , it defaults to A4 . If you leave out orientation , it defaults to Portrait .

This method was introduced in QtWebEngine 1.3.


void reload ()

Reloads the current page. This function is equivalent to the window.location.reload() DOM method.

另请参阅 reloadAndBypassCache() .


void reloadAndBypassCache ()

Reloads the current page, ignoring any cached content.

This method was introduced in QtWebEngine 1.1.

另请参阅 reload() .


void replaceMisspelledWord (const QString & replacement )

Replace the current misspelled word with replacement .

This method was introduced in QtWebEngine 1.3.


void runJavaScript ( string script , variant callback )

Runs the specified script in the content of the web view.

callback parameter is optional. If a callback function is provided, it will be invoked after the script finishes running.

runJavaScript("document.title", function(result) { console.log(result); });
								

Only plain data can be returned from JavaScript as the result value. Supported data types include all of the JSON data types as well as, for example, Date and ArrayBuffer . Unsupported data types include, for example, 函数 and Promise .

The script will run in the same world as other scripts that are part of the loaded site.

警告: Do not execute lengthy routines in the callback function, because it might block the rendering of the web content.

For more information about injecting scripts, see 脚本注入 . For an alternative way to inject scripts, see WebEngineView::userScripts .


void setActiveFocusOnPress ( bool arg )

Sets active focus to a clicked web engine view if arg is true . By setting it to false , a web engine view can be used to create a UI element that should not get focus. This can be useful in a hybrid UI.

This method was introduced in QtWebEngine 1.2.

另请参阅 activeFocusOnPress , activeFocusOnPressChanged ,和 WebEngineSettings::focusOnNavigationEnabled .


void stop ()

停止加载当前页面。


void triggerWebAction ( WebAction action )

触发 Web 动作 action .

This method was introduced in QtWebEngine 1.2.

另请参阅 WebAction .