PYQT实现简单的浏览器功能

主要的类

QMainWindow

提供一个有菜单条、锚接窗口(例如工具条)和一个状态条的主应用程序窗口。 http://www.kuqin.com/qtdocument/qmainwindow.html#details

QWebPage、QWebView

Pyqt的主要类说明: http://www.cnblogs.com/liqiu/p/3452269.html

其他

可以了解QT的文档:http://qt-project.org/doc/qt-4.8/

import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import * class MyBrowser(QWidget): def __init__(self, parent = None):
super(MyBrowser, self).__init__(parent)
self.createLayout()
self.createConnection()
def search(self):
address = str(self.addressBar.text())
if address:
if address.find('://') == -1:
address = 'http://' + address
url = QUrl(address)
self._view.load(url) def createLayout(self):
self.setWindowTitle("liqiu's browser") self.addressBar = QLineEdit()
self.goButton = QPushButton("Search") bl = QHBoxLayout()
bl.addWidget(self.addressBar)
bl.addWidget(self.goButton) self._page = QWebPage()
self._view = QWebView()
self._view.setPage(self._page)
self._window = QMainWindow()
self._window.setCentralWidget(self._view)
url = QUrl("http://www.taobao.com")
self._view.load(url)
layout = QVBoxLayout()
layout.addLayout(bl)
layout.addWidget(self._window) self.setLayout(layout) def createConnection(self):
self.connect(self.addressBar, SIGNAL('returnPressed()'), self.search)
self.connect(self.addressBar, SIGNAL('returnPressed()'), self.addressBar, SLOT('selectAll()'))
self.connect(self.goButton, SIGNAL('clicked()'), self.search)
self.connect(self.goButton, SIGNAL('clicked()'), self.addressBar, SLOT('selectAll()')) app = QApplication(sys.argv) browser = MyBrowser()
browser.show() sys.exit(app.exec_())
上一篇:[转贴]漫谈C语言及如何学习C语言


下一篇:angularJS directive详解(自定义指令)