• 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_())
  • 相关阅读:
    docker运行springboot应用
    docer运行node
    Git添加仓库
    安装docker-compose
    centos安装docker
    Centos设置软件源
    ubuntu安装docker
    ubuntu安装阿里云镜像地址
    docker加速器配置
    配置Spring发送邮件
  • 原文地址:https://www.cnblogs.com/liqiu/p/3464266.html
Copyright © 2020-2023  润新知