QML WebView ElementThe WebView item allows you to add Web content to a canvas. More... Inherits Item Inherited by basic, elements, javaScript, loadError, sethtml, and webviewbackgroundcolor. This element was introduced in Qt 4.7. Properties
Signal HandlersMethodsDetailed DescriptionA WebView renders Web content based on a URL. This type is made available by importing the QtWebKit module: import QtWebKit 1.0 The WebView item includes no scrolling, scaling, toolbars, or other common browser components. These must be implemented around WebView. See the QML Web Browser example for a demonstration of this. The page to be displayed by the item is specified using the url property, and this can be changed to fetch and display a new page. While the page loads, the progress property is updated to indicate how much of the page has been loaded. AppearanceIf the width and height of the item is not set, they will dynamically adjust to a size appropriate for the content. This width may be large for typical online web pages, typically greater than 800 by 600 pixels. If the width or height is explictly set, the rendered Web site will be clipped, not scaled, to fit into the set dimensions. If the preferredWidth property is set, the width will be this amount or larger, usually laying out the Web content to fit the preferredWidth. The appearance of the content can be controlled to a certain extent by changing the settings.standardFontFamily property and other settings related to fonts. The page can be zoomed by calling the heuristicZoom() method, which performs a series of tests to determine whether zoomed content will be displayed in an appropriate way in the space allocated to the item. User Interaction and NavigationBy default, certain mouse and touch events are delivered to other items in preference to the Web content. For example, when a scrolling view is created by placing a WebView in a Flickable, move events are delivered to the Flickable so that the user can scroll the page. This prevents the user from accidentally selecting text in a Web page instead of scrolling. The pressGrabTime property defines the time the user must touch or press a mouse button over the WebView before the Web content will receive the move events it needs to select text and images. When this item has keyboard focus, all keyboard input will be sent directly to the Web page within. When the navigates by clicking on links, the item records the pages visited in its internal history Because this item is designed to be used as a component in a browser, it exposes actions for back, forward, reload and stop. These can be triggered to change the current page displayed by the item. Example UsageThe following example displays a scaled down Web page at a fixed size. import QtWebKit 1.0 WebView { url: "http://www.nokia.com" preferredWidth: 490 preferredHeight: 400 scale: 0.5 smooth: false } See also WebView example and Web Browser demo. Property DocumentationThis property holds the action for causing the previous URL in the history to be displayed. This property holds the action for causing the next URL in the history to be displayed. This property holds HTML text set directly The html property can be set as a string. WebView { html: "<p>This is <b>HTML</b>." } A list of QML objects to expose to the web page. Each object will be added as a property of the web frame's window object. The property name is controlled by the value of WebView.windowObjectName attached property. Exposing QML objects to a web page allows JavaScript executing in the web page itself to communicate with QML, by reading and writing properties and by calling methods of the exposed QML objects. This example shows how to call into a QML method using a window object. WebView { javaScriptWindowObjects: QtObject { WebView.windowObjectName: "qml" function qmlCall() { console.log("This call is in QML!"); } } html: "<script>window.qml.qmlCall();</script>" } The output of the example will be: This call is in QML!
If Javascript is not enabled for the page, then this property does nothing. This property holds the component to use for new windows. The component must have a WebView somewhere in its structure. When the web engine requests a new window, it will be an instance of this component. The parent of the new window is set by newWindowParent. It must be set. The parent item for new windows. See also newWindowComponent. This property holds the ideal height for displaying the current URL. This only affects the area zoomed by heuristicZoom(). This property holds the ideal width for displaying the current URL. The number of milliseconds the user must press before the WebView starts passing move events through to the Web engine (rather than letting other QML elements such as a Flickable take them). Defaults to 400ms. Set to 0 to always grab and pass move events to the Web engine. This property holds the progress of loading the current URL, from 0 to 1. If you just want to know when progress gets to 1, use WebView::onLoadFinished() or WebView::onLoadFailed() instead. This property holds the action for reloading with the current URL These properties give access to the settings controlling the web view. See QWebSettings for details of these properties. WebView { settings.pluginsEnabled: true settings.standardFontFamily: "Arial" // ... } This property is the current status suggested by the current web page. In a web browser, such status is often shown in some kind of status bar. This property holds the action for stopping loading with the current URL This property holds the title of the web page currently viewed By default, this property contains an empty string. This property holds the URL to the page displayed in this item. It can be set, but also can change spontaneously (eg. because of network redirection). If the url is empty, the page is blank. The url is always absolute (QML will resolve relative URL strings in the context of the containing QML document). Signal Handler DocumentationThe handler is called when the web engine sends a JavaScript alert. The message is the text to be displayed in the alert to the user. The WebView does not pass double-click events to the web engine, but rather emits this signals. This handler is called when the web engine fails loading a page or any component content (WebView::onLoadFinished() will be emitted on success). This handler is called when the web engine successfully finishes loading a page, including any component content (WebView::onLoadFailed() will be emitted otherwise). See also progress. This handler is called when the web engine begins loading a page. Later, WebView::onLoadFinished() or WebView::onLoadFailed() will be emitted. Method DocumentationEvaluates the scriptSource JavaScript inside the context of the main web frame, and returns the result of the last executed statement. Note that this JavaScript does not have any access to QML objects except as made available as windowObjects. Finds a zoom that:
If such a zoom exists, emits zoomTo(zoom,centerX,centerY) and returns true; otherwise, no signal is emitted and returns false. |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.8 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com