Movatterモバイル変換


[0]ホーム

URL:


Back to Qt.io
Contact UsBlogDownload Qt
Qt documentation

WebEngineView QML Type

A WebEngineView renders web content within a QML application.More...

Import Statement: import QtWebEngine 1.10
Since: QtWebEngine 1.0
Inherits:

Item

Properties

Signals

Methods

Detailed Description

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

Initializing Web Engine

For the web engine view to be rendered, the web engine must be initialized by usingQtWebEngine::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);QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts);QtWebEngine::initialize();QGuiApplication app(argc, argv);QQmlApplicationEngine engine;    engine.load(QUrl(QStringLiteral("qrc:/main.qml")));return app.exec();}

Loading Web Pages

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

The history is represented by aWebEngineHistory data model that is held by thenavigationHistory property.

The following sample QML application loads a web page using theurl property:

import QtQuick 2.0import QtQuick.Window 2.0import QtWebEngine 1.0Window {width:1024height:750visible:trueWebEngineView {anchors.fill:parenturl:"https://www.qt.io"    }}

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

The title of an HTML page can be accessed with thetitle property. Additionally, a web page may specify an icon, which can be accessed using theicon property. ThezoomFactor property enables zooming the contents of the web page by a scale factor.

If a certificate error is raised while loading a web page, thecertificateError() signal is emitted. Certificate errors are handled by using the methods of theWebEngineCertificateError type.

Interaction

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. ThenewViewRequested() signal is emitted when a request to load the page in a separate web engine view is issued. TheNewViewDestination property describes how the new view should be opened. In addition, theWebEngineNewViewRequest utility type can be used to load web pages in separate web engine views.

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

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

ThefocusOnNavigationEnabled 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).

ThelinkHovered() signal is emitted when a mouse pointer passes over a link and thus corresponds to themouseover DOM event.

Actions, such as selecting and editing content, can be performed on a web page by using thetriggerWebAction() method. The available actions are described by theWebAction property.

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

User Scripts

During the loading of a page, so calleduser scripts can be injected in the JavaScript engine at different points. The script objects attached to the web engine view are held by theuserScripts property and injected by using theWebEngineScript type. Scripts can also be run by using therunJavaScript() method in the same world as other scripts that are part of the loaded site.

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

Fullscreen Mode

A web page can request through the JavaScript API to be loaded in fullscreen mode. ThefullScreenRequested() signal is emitted when the web page issues the request. TheFullScreenRequest utility type can be used to toggle fullscreen requests. ThefullScreenCancelled 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 theWebEngineProfile 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 aprivate browsing mode. The current profile for the view is held by theprofile property and the current settings are held by thesettings property. The settings are specified by using theWebEngineSettings type.

Platform Features

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

Rendering to OpenGL Surface

When using aQQuickRenderControl 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 byQtWebEngine::initialize, but there is no public API for accessing that context in order to share it with theQQuickRenderControl context.

To have the web engine view rendered correctly, it is possible to manually create a new offscreen context that is shared with theQQuickRenderControl and to call the non-public functionqt_gl_set_global_share_context(), rather than callinginitialize(). Ifinitialize() is called after setting a global context, it will do nothing.

Property Documentation

ErrorDomain :enumeration

Describes various high-level error types:

ConstantDescription
WebEngineView.NoErrorDomain 
WebEngineView.InternalErrorDomainContent fails to be interpreted by Qt WebEngine.
WebEngineView.ConnectionErrorDomainError results from faulty network connection.
WebEngineView.CertificateErrorDomainError related to the SSL/TLS certificate.
WebEngineView.HttpErrorDomainError related to the HTTP connection.
WebEngineView.FtpErrorDomainError related to the FTP connection.
WebEngineView.DnsErrorDomainError 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:

ConstantDescription
WebEngineView.GeolocationLocation hardware or service.
WebEngineView.MediaAudioCaptureAudio capture devices, such as microphones.
WebEngineView.MediaVideoCaptureVideo devices, such as cameras.
WebEngineView.MediaAudioVideoCaptureBoth audio and video capture devices.
DesktopVideoCaptureVideo output capture, that is, the capture of the user's display. (Added in Qt 5.10)
DesktopAudioVideoCaptureBoth audio and video output capture. (Added in Qt 5.10)
WebEnginView.NotificationsWeb notifications for the end-user.

See alsofeaturePermissionRequested() andgrantFeaturePermission().


FindFlags :enumeration

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

ConstantDescription
WebEngineView.FindBackwardSearches backwards instead of forwards.
WebEngineView.FindFlagsFindCaseSensitively By defaultfindText() works case insensitive. Specifying this option changes the behavior to a case sensitive find operation.

See alsofindText().


JavaScriptConsoleMessageLevel :enumeration

Indicates the severity of a JavaScript console message:

ConstantDescription
WebEngineView.InfoMessageLevelMessage is purely informative and can safely be ignored.
WebEngineView.WarningMessageLevelMessage indicates there might be a problem that may need attention.
WebEngineView.ErrorMessageLevelMessage indicates there has been an error.

LifecycleState :enumeration

This enum describes the lifecycle state of the page:

ConstantDescription
WebEngineView.LifecycleState.ActiveNormal state.
WebEngineView.LifecycleState.FrozenLow CPU usage state where most HTML task sources are suspended.
WebEngineView.LifecycleState.DiscardedVery low resource usage state where the entire browsing context is discarded.

This property was introduced in QtWebEngine 1.10.

See alsolifecycleState,Page Lifecycle API, andWebEngine Lifecycle Example.


LoadStatus :enumeration

Reflects a page's load status:

ConstantDescription
WebEngineView.LoadStartedStatusPage is currently loading.
WebEngineView.LoadStoppedStatusLoading the page was stopped by thestop() method or by the loader code or network stack in Chromium.
WebEngineView.LoadSucceededStatusPage has successfully loaded, and is not currently loading.
WebEngineView.LoadFailedStatusPage has failed to load, and is not currently loading.

NewViewDestination :enumeration

Describes how to open a new view:

ConstantDescription
WebEngineView.NewViewInWindowIn a separate Window.
WebEngineView.NewViewInTabIn a tab of the same window.
WebEngineView.NewViewInDialogIn a Window without a tab bar, toolbar, or URL bar.
WebEngineView.NewViewInBackgroundTabIn a tab of the same window, without hiding the currently visible web engine view.

See alsoWebEngineNewViewRequest.destination.


PrintedPageOrientation :enumeration

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

ConstantDescription
WebEngineView.PortraitThe document will be created using portrait orientation.
WebEngineView.LandscapeThe document will be created using landscape orientation.

This property was introduced in QtWebEngine 1.3.

See alsoWebEngineView::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 matchQPageSize::PageSizeId. They are also duplicated inQPagedPaintDevice andQPrinter.

The defined sizes are:

ConstantDescription
WebEngineView.A0841 x 1189 mm
WebEngineView.A1594 x 841 mm
WebEngineView.A2420 x 594 mm
WebEngineView.A3297 x 420 mm
WebEngineView.A4210 x 297 mm, 8.26 x 11.69 inches
WebEngineView.A5148 x 210 mm
WebEngineView.A6105 x 148 mm
WebEngineView.A774 x 105 mm
WebEngineView.A852 x 74 mm
WebEngineView.A937 x 52 mm
WebEngineView.B01000 x 1414 mm
WebEngineView.B1707 x 1000 mm
WebEngineView.B2500 x 707 mm
WebEngineView.B3353 x 500 mm
WebEngineView.B4250 x 353 mm
WebEngineView.B5176 x 250 mm, 6.93 x 9.84 inches
WebEngineView.B6125 x 176 mm
WebEngineView.B788 x 125 mm
WebEngineView.B862 x 88 mm
WebEngineView.B944 x 62 mm
WebEngineView.B1031 x 44 mm
WebEngineView.C5E163 x 229 mm
WebEngineView.Comm10E105 x 241 mm, U.S. Common 10 Envelope
WebEngineView.DLE110 x 220 mm
WebEngineView.Executive7.5 x 10 inches, 190.5 x 254 mm
WebEngineView.Folio210 x 330 mm
WebEngineView.Ledger431.8 x 279.4 mm
WebEngineView.Legal8.5 x 14 inches, 215.9 x 355.6 mm
WebEngineView.Letter8.5 x 11 inches, 215.9 x 279.4 mm
WebEngineView.Tabloid279.4 x 431.8 mm
WebEngineView.CustomUnknown, 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.

See alsoWebEngineView::printToPdf().


RenderProcessTerminationStatus :enumeration

Describes the status with which the render process terminated:

ConstantDescription
WebEngineView.NormalTerminationStatusThe render process terminated normally.
WebEngineView.AbnormalTerminationStatusThe render process terminated with a non-zero exit status.
WebEngineView.CrashedTerminationStatusThe render process crashed, for example because of a segmentation fault.
WebEngineView.KilledTerminationStatusThe render process was killed, for example bySIGKILL or task manager kill.

This property was introduced in QtWebEngine 1.2.


WebAction :enumeration

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

ConstantDescription
WebEngineView.NoWebActionNo action is triggered.
WebEngineView.BackNavigate back in the history of navigated links.
WebEngineView.ForwardNavigate forward in the history of navigated links.
WebEngineView.StopStop loading the current page.
WebEngineView.ReloadReload the current page.
WebEngineView.ReloadAndBypassCacheReload the current page, but do not use any local cache.
WebEngineView.CutCut the content currently selected into the clipboard.
WebEngineView.CopyCopy the content currently selected into the clipboard.
WebEngineView.PastePaste content from the clipboard.
WebEngineView.UndoUndo the last editing action.
WebEngineView.RedoRedo the last editing action.
WebEngineView.SelectAllSelect all content. This action is only enabled when the page's content is focused. The focus can be forced by the JavaScriptwindow.focus() call, or thefocusOnNavigationEnabled setting should be enabled to get automatic focus.
WebEngineView.PasteAndMatchStylePaste content from the clipboard with current style.
WebEngineView.OpenLinkInThisWindowOpen the current link in the current window. (Added in Qt 5.6)
WebEngineView.OpenLinkInNewWindowOpen the current link in a new window. Requires a handler for thenewViewRequested() signal. (Added in Qt 5.6)
WebEngineView.OpenLinkInNewTabOpen the current link in a new tab. Requires a handler for thenewViewRequested() signal. (Added in Qt 5.6)
WebEngineView.CopyLinkToClipboardCopy the current link to the clipboard. (Added in Qt 5.6)
WebEngineView.CopyImageToClipboardCopy the clicked image to the clipboard. (Added in Qt 5.6)
WebEngineView.CopyImageUrlToClipboardCopy the clicked image's URL to the clipboard. (Added in Qt 5.6)
WebEngineView.CopyMediaUrlToClipboardCopy the hovered audio or video's URL to the clipboard. (Added in Qt 5.6)
WebEngineView.ToggleMediaControlsToggle between showing and hiding the controls for the hovered audio or video element. (Added in Qt 5.6)
WebEngineView.ToggleMediaLoopToggle whether the hovered audio or video should loop on completetion or not. (Added in Qt 5.6)
WebEngineView.ToggleMediaPlayPauseToggle the play/pause state of the hovered audio or video element. (Added in Qt 5.6)
WebEngineView.ToggleMediaMuteMute or unmute the hovered audio or video element. (Added in Qt 5.6)
WebEngineView.DownloadLinkToDiskDownload the current link to the disk. To implement download actions, connect to theWebEngineProfile.downloadRequested signal. (Added in Qt 5.6)
WebEngineView.DownloadImageToDiskDownload the highlighted image to the disk. (Added in Qt 5.6)
WebEngineView.DownloadMediaToDiskDownload the hovered audio or video to the disk. (Added in Qt 5.6)
WebEngineView.InspectElementTrigger any attached Web Inspector to inspect the highlighed element. (Added in Qt 5.6)
WebEngineView.ExitFullScreenExit the fullscreen mode. (Added in Qt 5.6)
WebEngineView.SavePageSave the current web page to disk. (Added in Qt 5.7)
WebEngineView.ViewSourceShow the source of the current page in a new tab. Requires a handler for thenewViewRequested() signal. (Added in Qt 5.8)
WebEngineView.ToggleBoldToggles boldness for the selection or at the cursor position. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.ToggleItalicToggles italics for the selection or at the cursor position. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.ToggleUnderlineToggles underlining of the selection or at the cursor position. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.ToggleStrikethroughToggles striking through the selection or at the cursor position. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.AlignLeftAligns the lines containing the selection or the cursor to the left. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.AlignCenterAligns the lines containing the selection or the cursor at the center. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.AlignRightAligns the lines containing the selection or the cursor to the right. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.AlignJustifiedStretches the lines containing the selection or the cursor so that each line has equal width. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.IndentIndents the lines containing the selection or the cursor. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.OutdentOutdents the lines containing the selection or the cursor. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.InsertOrderedListInserts an ordered list at the current cursor position, deleting the current selection. Requirescontenteditable="true". (Added in Qt 5.10)
WebEngineView.InsertUnorderedListInserts an unordered list at the current cursor position, deleting the current selection. Requirescontenteditable="true". (Added in 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 istrue.

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.

See alsorecentlyAudible.


backgroundColor :bool

Changes the color of theWebEngineView'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.

The default value is white.

This property was introduced in QtWebEngine 1.2.


[read-only]canGoBack :bool

Returnstrue if there are prior session history entries,false otherwise.


[read-only]canGoForward :bool

Returnstrue if there are subsequent session history entries,false otherwise.


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.

See alsoinspectedView.


[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 theicon property to build anImage component:

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

Specifying thesourceSize property of theImage 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. IfsourceSize 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 inspectedWebEngineView.

This property was introduced in QtWebEngine 1.7.

See alsodevToolsView.


[read-only]isFullScreen :bool

Returnstrue if the web view is in fullscreen mode,false otherwise.

This property was introduced in QtWebEngine 1.1.

See alsofullScreenRequested() andfullScreenCancelled().


lifecycleState :LifecycleState

The current lifecycle state of the page.

The following restrictions are enforced by the setter:

  • A visible page must remain in theActive state.
  • If the page is being inspected by adevToolsView then both pages must remain in theActive states.
  • A page in theDiscarded state can only transition to theActive state. This will cause a reload of the page.

These are the only hard limits on the lifecycle state, but see alsorecommendedState for the recommended soft limits.

This property was introduced in QtWebEngine 1.10.

See alsorecommendedState,Page Lifecycle API, andWebEngine Lifecycle Example.


[read-only]loadProgress :int

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


[read-only]loading :bool

Returnstrue if the HTML page is currently loading,false otherwise.


[read-only]navigationHistory :WebEngineHistory

The navigation history of the current view.

This property was introduced in QtWebEngine 1.1.

See alsoWebEngineHistory.


The current profile used for the view.

This property was introduced in QtWebEngine 1.1.

See alsoWebEngineProfile.


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

See alsoaudioMuted andrecentlyAudibleChanged.


recommendedState :LifecycleState

The recommended limit for the lifecycle state of the page.

Setting the lifecycle state to a lower resource usage state than the recommended state may cause side-effects such as stopping background audio playback or loss of HTML form input. Setting the lifecycle state to a higher resource state is however completely safe.

This property was introduced in QtWebEngine 1.10.

See alsolifecycleState,Page Lifecycle API, andWebEngine Lifecycle Example.


[read-only]renderProcessPid :qint64

Returns the process ID (PID) of the render process assigned to the current page's main frame.

If no render process is available yet,0 is returned.

This property was introduced in QtWebEngine 1.11.

See alsorenderProcessPidChanged.


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.

See alsoWebEngineSettings.


[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 thewindow.location DOM property.

See alsoloadHtml().


[read-only]userScripts :list<WebEngineScript>

List of script objects attached to the view.

This property was introduced in QtWebEngine 1.1.

See alsoWebEngineScript.


webChannel :QQmlWebChannel

The web channel instance used by this view. This channel is automatically using the internalQtWebEngine transport mechanism over Chromium IPC, and exposed in the javascript context of the page it is rendering asqt.webChannelTransport. This transport object is used when instantiating the JavaScript counterpart ofQWebChannel using theQt WebChannel JavaScript API.

Note: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 between0 and256.

This property was introduced in QtWebEngine 1.3.


zoomFactor :real

Zoom factor for the view. Valid values are within the range from0.25 to5.0. The default factor is1.0.

This property was introduced in QtWebEngine 1.1.


Signal Documentation

activeFocusOnPressChanged(boolactiveFocusOnPress)

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

Note:The corresponding handler isonActiveFocusOnPressChanged.

This signal was introduced in QtWebEngine 1.2.

See alsoactiveFocusOnPress andsetActiveFocusOnPress().


audioMutedChanged(boolmuted)

This signal is emitted when the value ofmuted changes. The value is specified using theaudioMuted property.

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

Note:The corresponding handler isonAudioMutedChanged.

This signal was introduced in QtWebEngine 1.3.

See alsoaudioMuted andrecentlyAudibleChanged.


authenticationDialogRequested(AuthenticationDialogRequestrequest)

This signal is emitted when an authentication dialog is requested.

Therequest can be handled by using the methods of theAuthenticationDialogRequest type.

Note:Signal handlers need to callrequest.accepted = true to prevent a default dialog from showing up. Make sure to call eitherAuthenticationDialogRequest::dialogAccept() orAuthenticationDialogRequest::dialogReject() afterwards.

Note:The corresponding handler isonAuthenticationDialogRequested.

This signal was introduced in QtWebEngine 1.4.


backgroundColorChanged()

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

Note:The corresponding handler isonBackgroundColorChanged.

This signal was introduced in QtWebEngine 1.2.


certificateError(WebEngineCertificateErrorerror)

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 theWebEngineCertificateError type.

Note:The corresponding handler isonCertificateError.

This signal was introduced in QtWebEngine 1.1.


colorDialogRequested(ColorDialogRequestrequest)

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

Therequest can be handled by using the methods of theColorDialogRequest type.

Note:Signal handlers need to callrequest.accepted = true to prevent a default dialog from showing up. Make sure to call eitherColorDialogRequest::dialogAccept() orColorDialogRequest::dialogReject() afterwards.

Note:The corresponding handler isonColorDialogRequested.

This signal was introduced in QtWebEngine 1.4.


contextMenuRequested(ContextMenuRequestrequest)

This signal is emitted when a context menu is requested.

Therequest can be handled by using the properties of theContextMenuRequest type.

Note:Signal handlers need to callrequest.accepted = true to prevent a default context menu from showing up.

Note:The corresponding handler isonContextMenuRequested.

This signal was introduced in QtWebEngine 1.4.


featurePermissionRequested(urlsecurityOrigin,Featurefeature)

This signal is emitted when the web site identified bysecurityOrigin requests to make use of the resource or device identified byfeature.

Note:The corresponding handler isonFeaturePermissionRequested.

This signal was introduced in QtWebEngine 1.1.

See alsograntFeaturePermission().


fileDialogRequested(FileDialogRequestrequest)

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

Therequest can be handled by using the methods of theFileDialogRequest type.

Note:Signal handlers need to callrequest.accepted = true to prevent a default dialog from showing up. Make sure to call eitherFileDialogRequest::dialogAccept() orFileDialogRequest::dialogReject() afterwards.

Note:The corresponding handler isonFileDialogRequested.

This signal was introduced in QtWebEngine 1.4.


findTextFinished(FindTextResultresult)

This signal is emitted when a string search on a page is completed.result is the result of the string search.

Note:The corresponding handler isonFindTextFinished.

This signal was introduced in QtWebEngine 1.10.

See alsofindText() andFindTextResult.


fullScreenRequested(FullScreenRequestrequest)

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

Note:The corresponding handler isonFullScreenRequested.

This signal was introduced in QtWebEngine 1.1.

See alsoisFullScreen.


geometryChangeRequested(rectgeometry,rectframeGeometry)

This signal is emitted whenever the document wants to change the position and size of the page toframeGeometry. This can happen for example through JavaScript.

WhileframeGeometry includes,geometry excludes the size of frame margins.

Note:Geometry related properties of QML Window expect a size excluding the window decoration. You have to usegeometry to handle this signal correctly.

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

Note:The corresponding handler isonGeometryChangeRequested.

This signal was introduced in QtWebEngine 1.7.


javaScriptConsoleMessage(JavaScriptConsoleMessageLevellevel,stringmessage,intlineNumber,stringsourceID)

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

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

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 ajslogging category.

Note:The corresponding handler isonJavaScriptConsoleMessage.

See alsoConsole Logging.


javaScriptDialogRequested(JavaScriptDialogRequestrequest)

This signal is emitted when a JavaScript dialog is requested.

Therequest can be handled by using the methods of theJavaScriptDialogRequest type.

Note:Signal handlers need to callrequest.accepted = true to prevent a default dialog from showing up. Make sure to call eitherJavaScriptDialogRequest::dialogAccept() orJavaScriptDialogRequest::dialogReject() afterwards.

Note:The corresponding handler isonJavaScriptDialogRequested.

This signal was introduced in QtWebEngine 1.4.


linkHovered(urlhoveredUrl)

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

Note:The corresponding handler isonLinkHovered.


loadingChanged(WebEngineLoadRequestloadRequest)

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

When handling the signal withonLoadingChanged, various read-only parameters are available on theWebEngineLoadRequest specified byloadRequest.

Note:The corresponding handler isonLoadingChanged.

See alsoloading,LoadStatus, andErrorDomain.


navigationRequested(WebEngineNavigationRequestrequest)

This signal is emitted when the navigation requestrequest is issued.

Note:The corresponding handler isonNavigationRequested.


newViewRequested(WebEngineNewViewRequestrequest)

This signal is emitted whenrequest 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 towindow.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!">');    }    propertyComponentwindowComponent: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        propertyWebEngineViewwebView: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);            }        }    }}

Note:The corresponding handler isonNewViewRequested.

This signal was introduced in QtWebEngine 1.1.

See alsoNewViewDestination andWebEngine Quick Nano Browser.


pdfPrintingFinished(stringfilePath,boolsuccess)

This signal is emitted when printing the web page into a PDF file has finished.filePath will contain the path the file was requested to be created at, andsuccess will betrue if the file was successfully created andfalse otherwise.

Note:The corresponding handler isonPdfPrintingFinished.

This signal was introduced in QtWebEngine 1.5.

See alsoprintToPdf().


printRequest()

This signal is emitted when the JavaScriptwindow.print() method is called. Typically, the signal handler can simply callprintToPdf().

Note:The corresponding handler isonPrintRequest.

This signal was introduced in QtWebEngine 1.8.

See alsoprintToPdf.


quotaRequested(QuotaRequestrequest)

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

Note:The corresponding handler isonQuotaRequested.

This signal was introduced in QtWebEngine 1.7.

See alsoQuotaRequest.


recentlyAudibleChanged(boolrecentlyAudible)

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

Note:The signal is also emitted when theaudioMuted property changes. Also if the audio is paused, this signal is emitted with an approximatetwo-second delay, from the moment the audio is paused.

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 oftrue, and then with a value offalse. Further, when audio starts playing, the signal is emitted twice with a value oftrue.

Note:The corresponding handler isonRecentlyAudibleChanged.

This signal was introduced in QtWebEngine 1.3.

See alsorecentlyAudible.


registerProtocolHandlerRequested(RegisterProtocolHandlerRequestrequest)

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

Note:The corresponding handler isonRegisterProtocolHandlerRequested.

This signal was introduced in QtWebEngine 1.7.

See alsoRegisterProtocolHandlerRequest.


renderProcessPidChanged(qint64pid)

If no render process is available yet,0 is returned. This signal is emitted when the PID (process ID) of the page's underlying render process changed.

Note:The corresponding handler isonRenderProcessPidChanged.

This signal was introduced in QtWebEngine 1.11.

See alsorenderProcessPid.


renderProcessTerminated(RenderProcessTerminationStatusterminationStatus,intexitCode)

This signal is emitted when the render process is terminated with a non-zero exit status.terminationStatus is the termination status of the process andexitCode is the status code with which the process terminated.

Note:The corresponding handler isonRenderProcessTerminated.

This signal was introduced in QtWebEngine 1.2.

See alsoRenderProcessTerminationStatus.


selectClientCertificate(WebEngineClientCertificateSelectionclientCertificateSelection)

This signal is emitted when a web site requests an SSL client certificate, and one or more were found in the system's client certificate store.

Handling the signal is asynchronous, and loading will be waiting until a certificate is selected, or the last copy ofclientCertificateSelection is destroyed.

If the signal is not handled,clientCertificateSelection is automatically destroyed, and loading will continue without a client certificate.

Note:The corresponding handler isonSelectClientCertificate.

This signal was introduced in QtWebEngine 1.9.

See alsoWebEngineClientCertificateSelection.


tooltipRequested(TooltipRequestrequest)

This signal is emitted when the web page sends arequest to show a tooltip at a specified position.

Note:Signal handlers need to callrequest.accepted = true to prevent a default tooltip from showing up.

Note:The corresponding handler isonTooltipRequested.

This signal was introduced in QtWebEngine 1.10.

See alsoTooltipRequest.


wasRecentlyAudibleChanged(boolwasRecentlyAudible)

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

Note:The signal is also emitted when calling the setAudioMuted method.

Note:The corresponding handler isonWasRecentlyAudibleChanged.

This signal was introduced in QtWebEngine 1.3.


windowCloseRequested()

This signal is emitted whenever the page requests the web browser window to be closed, for example through the JavaScriptwindow.close() call.

Note:The corresponding handler isonWindowCloseRequested.

This signal was introduced in QtWebEngine 1.2.


Method Documentation

WebEngineActionaction(WebActionaction)

Returns aWebEngineAction for the specifiedWebActionaction.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.

See alsoWebEngineAction.


voidfindText(stringsubString,FindFlagsoptions,variantresultCallback)

Finds the specified string,subString, in the page, using the givenoptions. ThefindTextFinished() signal is emitted when a string search is completed.

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

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

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

This method was introduced in QtWebEngine 1.1.

See alsofindTextFinished().


voidfindText(stringsubString,FindFlagsoptions)

Finds the specified string,subString, in the page, using the givenoptions. ThefindTextFinished() signal is emitted when a string search is completed.

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

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

This method was introduced in QtWebEngine 1.1.

See alsofindTextFinished().


voidfindText(stringsubString)

Finds the specified string,subString, in the page. ThefindTextFinished() signal is emitted when a string search is completed.

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

This method was introduced in QtWebEngine 1.1.

See alsofindTextFinished().


voidfullScreenCancelled()

Immediately setsisFullScreen property tofalse. 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.

See alsoisFullScreen andfullScreenRequested().


voidgoBack()

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

See alsocanGoBack.


voidgoBackOrForward(intoffset)

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

See alsogoBack() andgoForward().


voidgoForward()

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


voidgrantFeaturePermission(urlsecurityOrigin,Featurefeature,boolgranted)

Sets or unsets the permission, depending ongranted, for the web site identified bysecurityOrigin to usefeature.

This method was introduced in QtWebEngine 1.1.

See alsofeaturePermissionRequested().


voidloadHtml(stringhtml,urlbaseUrl)

Loads the specifiedhtml as the content of the web view.

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

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

See alsourl.


voidprintToPdf(variantresultCallback,PrintedPageSizeIdpageSizeId,PrintedPageOrientationorientation)

Prints theWebEngineView's current content to a PDF document and returns it in a byte array. The document's size will be determined by the value ofpageSizeId and its orientation will be determined usingorientation.

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

If you leave outpageSizeId, it defaults toA4. If you leave outorientation, it defaults toPortrait.

This method was introduced in QtWebEngine 1.3.


voidprintToPdf(conststringfilePath,PrintedPageSizeIdpageSizeId,PrintedPageOrientationorientation)

Prints theWebEngineView's current content to a PDF document and stores it underfilePath. The document's size will be determined by the value ofpageSizeId and its orientation will be determined usingorientation.

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 signalpdfPrintingFinished().

If you leave outpageSizeId, it defaults toA4. If you leave outorientation, it defaults toPortrait.

This method was introduced in QtWebEngine 1.3.

See alsopdfPrintingFinished().


voidreload()

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

See alsoreloadAndBypassCache().


voidreloadAndBypassCache()

Reloads the current page, ignoring any cached content.

This method was introduced in QtWebEngine 1.1.

See alsoreload().


voidreplaceMisspelledWord(constQString &replacement)

Replace the current misspelled word withreplacement.

This method was introduced in QtWebEngine 1.3.


voidrunJavaScript(stringscript,variantcallback)

Runs the specifiedscript in the content of the web view.

Thecallback 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 andArrayBuffer. Unsupported data types include, for example,Function andPromise.

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

Warning: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, seeScript Injection. For an alternative way to inject scripts, seeWebEngineView::userScripts.


voidsetActiveFocusOnPress(boolarg)

Sets active focus to a clicked web engine view ifarg istrue. By setting it tofalse, 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.

See alsoactiveFocusOnPress,activeFocusOnPressChanged, andWebEngineSettings::focusOnNavigationEnabled.


voidstop()

Stops loading the current page.


voidtriggerWebAction(WebActionaction)

Triggers the web actionaction.

This method was introduced in QtWebEngine 1.2.

See alsoWebAction.


© 2025 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 theGNU 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.

Contents

Qt Group includes The Qt Company Oy and its global subsidiaries and affiliates.


[8]ページ先頭

©2009-2025 Movatter.jp