QT基于QtWebkit实现浏览器的基本知识点

来源:互联网 发布:电脑没网络手机能连上 编辑:程序博客网 时间:2024/06/16 02:34

本文由Markdown语法编辑器编辑完成。

1. QtWebkit

QtWebkit是Qt对Apple公司webkit的支持而开发的库,主要包括以下几个类:

1.1 QWebDatabase
Access to HTML5 databases created with JavaScript.

1.2 QWebFrame
Represents a frame in a web page.

1.3 QWebHistory
Represents the history of a QWebPage.

1.4 QWebHistoryInterface
Interface to implement link history.

1.5 QWebHistoryItem
Represents one item in the history of a QWebPage.

1.6 QWebHitTestResult
Information about the web page content after a hit

1.7 QWebPage
Object to view and edit web documents.

1.8 QWebPluginFactory
Creates plugins to be embedded into web pages.

1.9 QWebSecurityOrigin
Defines a security boundary for web sites.

1.10 QWebSettings
Object to store the settings used by QWebPage and QWebView.

1.11 QWebView
Widget that is used to view and edit web document.

2. 基于QtWebkit开发的浏览器的问题解决

2.1 弹出窗口中当鼠标光标在input编辑框,焦点不在编辑框时键盘的退格键失效

解决方案:
在QWebview的派生类Webview中增加keyPressEvent事件,增加对需要特殊处理的按键(如:Qt::Key_Backspace或Qt::Key_Enter)相关事务的逻辑判断,分析完成后,再调用基类的keyPressEvent事件。

关于如何从QT的浏览器中寻找某一类性质的元素的方法,请参照一下链接的方法:
https://stackoverflow.com/questions/2067281/qwebview-get-content-type

具体到本案例,逻辑判断为:

void WebView::keyPressEvent(QKeyEvent *event){    if (event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Back) {                   QWebElementCollection collection =  page()->mainFrame()->findAllElements("input[type=text]");        foreach (QWebElement element, collection) {            if (element.hasFocus()) {                               QWebView::keyPressEvent(event);                return;            }        }        return;    }    QWebView::keyPressEvent(event);}

参考链接:

  1. QtWebkit各个类之间关系-QWebView-QWebPage
    http://blog.sina.com.cn/s/blog_523491650100j3td.html
  2. QtWebkit模块介绍
    http://blog.csdn.net/niu2006/article/details/6003246
  3. QtWebkit中的memorycache机制
    http://blog.csdn.net/niu2006/article/details/7757923
  4. QtWebkit(Open Source Web Browser Engine)官网:
    https://webkit.org/
原创粉丝点击