Use the WebView API to create a browser, webviewapi

Source: Internet
Author: User

Use the WebView API to create a browser, webviewapi

We can see that there is a WebView In the Ubuntu SDK. It does not use the Qt standard Webkit library. On Ubuntu, we have made a lot of optimizations (oxide engine) to the following engine, which makes our WebView more superior in performance.


The following uses an example to design a simple Browser.


import QtQuick 2.0import Ubuntu.Components 1.1import Ubuntu.Web 0.2import QtQuick.Layouts 1.1/*!    \brief MainView with a Label and Button elements.*/MainView {    // objectName for functional testing purposes (autopilot-qt5)    objectName: "mainView"    // Note! applicationName needs to match the "name" field of the click manifest    applicationName: "browser.liu-xiao-guo"    /*     This property enables the application to change orientation     when the device is rotated. The default is false.    */    //automaticOrientation: true    // Removes the old toolbar and enables new features of the new header.    useDeprecatedToolbar: false    width: units.gu(100)    height: units.gu(75)    Page {        title: i18n.tr("")        RowLayout {            id:toolbar            anchors.top: parent.top            width: parent.width            height: units.gu(8)            spacing: units.gu(1)            Icon {                id: back                anchors.verticalCenter: parent.verticalCenter                name: "go-previous"                height: input.height                width: height                visible: webview.canGoBack                MouseArea {                    anchors.fill: parent                    onClicked: webview.goBack();                }            }            Icon {                id: forward                anchors.verticalCenter: parent.verticalCenter                name: "go-next"                height: input.height                width: height                visible: webview.canGoForward                MouseArea {                    anchors.fill: parent                    onClicked: webview.goForward();                }            }            TextField {                id: input                anchors.verticalCenter: parent.verticalCenter                height: parent.height - units.gu(1)                Layout.maximumWidth: parent.width                Layout.preferredWidth: parent.width - back.width - forward.width                text: "http://www.baidu.com"                onAccepted: {                    webview.url = input.text                }            }        }        WebView {            id: webview            anchors.top: toolbar.bottom            height: parent.height - toolbar.height            width: parent.width            url: "http://www.baidu.com"        }    }}


Here we use:

Import Ubuntu. Web 0.2

Module. We use two icons to return or forward. At the same time, we designed a TextField to input the address we want to go. Note that the address must be a string starting with http. When we press enter, the page will be opened by ourselves.




There is not much code, but it completes what we want to accomplish.

Source code for the entire project in: git clone https://gitcafe.com/ubuntu/browser.git



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.