一.首先,讓我們展示一幅QWebView的網頁:
想要實現上面的效果很簡單,你只需要完成三個步驟
1.建立一個QWebView對象,QWebView *view = new QWebView(parent);其中parent為父類.如果想要QWebView為top window,可以設定parent = 02.調用load或setUrl方法設定要顯示的網頁.注意網頁的格式以http://開頭3.調用show方法顯示QWebView 完整的代碼為:QWebView *view = new QWebView(parent); //步驟1view->load(QUrl("http://qtsoftware.com/")); //步驟2view->show(); //步驟3 二.QWebView除了用load方法設定網頁路徑外,也可以使用setHtml方法載入html格式的網頁,這裡我們以載入google地圖外掛程式為例.最後的為:
1.第一步,我們通過google地圖擷取外掛程式的代碼。進入google地圖頁面,點選連結,擷取代碼
2.擷取到得代碼為:<iframe width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src="http://ditu.google.cn/maps?hl=zh-CN&q=%E5%9C%B0%E5%9B%BE&ie=UTF8&brcurrent=3,0x31508e64e5c642c1:0x951daa7c349f366f,0%3B5,0,0&ll=38.005263,115.357367&spn=15.390188,22.535491&output=embed"></iframe><br /><small><a href="http://ditu.google.cn/maps?hl=zh-CN&q=%E5%9C%B0%E5%9B%BE&ie=UTF8&brcurrent=3,0x31508e64e5c642c1:0x951daa7c349f366f,0%3B5,0,0&ll=38.005263,115.357367&spn=15.390188,22.535491&source=embed" style="color:#0000FF;text-align:left">查看大圖</a></small>我們可以刪去br、small和a標記,最後在代碼前後添加<html></html>標記將檔案儲存為*.html(註:刪除的部分為屏蔽google地圖的右鍵效果,可以保留)3.調用QWebView的setHtml方法設定上述檔案的路徑,然後用show方法顯示google地圖
本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/chuckGao/archive/2009/08/26/4487157.aspx