In the 4.4 release of Qt bindings to WebKit have been added. WebKit is a web page rendering engine, that is used in Safari and Google Chrome. Qt bindings are also available in PyQt and in other languages. To get qt-webkit we need just Qt and PyQt 4.4 or newer. Linux users have to check if they have "qt-webkit" installed (if qt comes in several packages). After installing you should see "QWebView" in QtDesiger, in the "Display Widgets" section.
Here is a basic QWebView usage:Sample result:
Functionality of the "browser" is currently low, but WebKit bindings provide a lot of goodies. The loaded page becomes QWebPage object, which has its own URL history - QWebHistory. Also QWebView can send some signals - page loading progress, link clicked in the web page and more.
Now we will make more functional example browser. We will use QtDesiger to make the UI containing buttons for: back, forward, stop and reload page, URL bar (QLineEdit) and QWebView. Here is the sample design (saved as httpWidget.ui):Now we make a Python class from that UI:
- Connect signals with slots
- QWebView signals (like page loading status, page title)
- Buttons signals
- UI look configuration
- url_changed - user changed URL in QLineEdit - get it and load the page (validation still missing)
- stop_page - stop button clicked, stop page loading
- title_changed - QWebView sends page title, when the page is loaded, we can use it to set the window title
- reload_page - reload button clicked, we reload the web page
- link_clicked - a link on the web page has been clicked, we update the QLineEdit url
- load_progress - if the progress is 100 we can disable the stop button
- back - back button - go one URL back in the history
- next - next button - go one URL next in the history