由于目前Qt的webenginewidgets對Android還不支持,這里只能用QML的webview。
①、在PRo中添加:QT += webview
②、引用頭文件import QtWebView 1.1(注意,由于只適用于Android,所以Qt沒做補全功能)
③、直接用就可以了:
WebView {
anchors.fill: parent
url: "http://www.baidu.com"
}
這樣就可以用了,是不是很簡單嘞?
以下是我做的小樣,可以參考:
import QtQuick 2.6import QtQuick.Window 2.2import QtWebView 1.1Window {visible: trueproperty int tmpHei: width > height ? height/8.0 :height/16.0Rectangle{id:titlex:0y:0width: parent.width - tmpHeiheight: tmpHeicolor: "yellow"TextInput {id:textInputanchors.verticalCenter: parent.verticalCenteranchors.left: title.leftfont.pixelSize: tmpHei/2text: qsTr("http://www.baidu.com")color: "red"}}Rectangle {id:btny:0anchors.left: title.rightwidth: tmpHeiheight: tmpHeicolor: "black"Text {anchors.centerIn: parentfont.pixelSize: tmpHei/2text: qsTr("Go")color: "white"}MouseArea{anchors.fill: parentonClicked: {webView.url = "http://" + textInput.text}}}WebView {id:webViewx:0anchors.top: title.bottomwidth: parent.widthheight: parent.height - tmpHeiurl: "http://www.baidu.com"}}
新聞熱點
疑難解答