如何使PyQt5应用程序响应

时间:2019-02-18 07:07:22

标签: python python-2.7 pyqt5

我正在使用PyQt5和Python开发浏览器应用程序。我必须使其响应。我试图更改setGeometry()尺寸,但不起作用。

如果您能帮助我,将不胜感激。

Python版本3.7.2

from PyQt5 import QtCore, QtGui, QtWidgets            # +++ QtWidgets
from PyQt5 import QtWebEngineWidgets


class Ui_MainWindow(object): 
    def back(self):    self.webView.back() 
    def forword(self): self.webView.forward() 
    def reload(self):  self.webView.reload()

    def home(self):
        self.webView.load(QtCore.QUrl("http://pyxisad.com"))
    def search(self):
        url = self.ln_addressbar.text()
        self.webView.load(QtCore.QUrl(url))

    def setupUi(self, MainWindow):
        MainWindow.setObjectName("PyxisAd")
        MainWindow.resize(1000, 1000)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.tb_back = QtWidgets.QToolButton(self.centralwidget)
        self.tb_back.setGeometry(QtCore.QRect(10, 20, 41, 31))
        icon = QtGui.QIcon()
        icon.addPixmap(QtGui.QPixmap("icons/back.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tb_back.setIcon(icon)
        self.tb_back.setIconSize(QtCore.QSize(32, 32))
        self.tb_back.setObjectName("tb_back")
        ############### Event #############################
        self.tb_back.clicked.connect(self.back)
        ##################################################
        self.tb_reload = QtWidgets.QToolButton(self.centralwidget)
        self.tb_reload.setGeometry(QtCore.QRect(60, 20, 41, 31))
        icon1 = QtGui.QIcon()
        icon1.addPixmap(QtGui.QPixmap("icons/reload.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tb_reload.setIcon(icon1)
        self.tb_reload.setIconSize(QtCore.QSize(32, 32))
        self.tb_reload.setObjectName("tb_reload")
        ############### Event #############################3
        self.tb_reload.clicked.connect(self.reload)
        ##################################################
        self.tb_forword_2 = QtWidgets.QToolButton(self.centralwidget)
        self.tb_forword_2.setGeometry(QtCore.QRect(110, 20, 41, 31))
        icon2 = QtGui.QIcon()
        icon2.addPixmap(QtGui.QPixmap("icons/forword.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tb_forword_2.setIcon(icon2)
        self.tb_forword_2.setIconSize(QtCore.QSize(32, 32))
        self.tb_forword_2.setObjectName("tb_forword_2")
        ############### Event #############################3
        self.tb_forword_2.clicked.connect(self.forword)
        ##################################################
        self.tb_home = QtWidgets.QToolButton(self.centralwidget)
        self.tb_home.setGeometry(QtCore.QRect(160, 20, 41, 31))
        icon3 = QtGui.QIcon()
        icon3.addPixmap(QtGui.QPixmap("icons/home.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tb_home.setIcon(icon3)
        self.tb_home.setIconSize(QtCore.QSize(32, 32))
        self.tb_home.setObjectName("tb_home")
        ############### Event #############################3
        self.tb_home.clicked.connect(self.home)
        ##################################################
        self.ln_addressbar = QtWidgets.QLineEdit(self.centralwidget)
        self.ln_addressbar.setGeometry(QtCore.QRect(210, 20, 491, 31))
        self.ln_addressbar.setObjectName("ln_addressbar")


        self.tb_search = QtWidgets.QToolButton(self.centralwidget)
        self.tb_search.setGeometry(QtCore.QRect(710, 20, 41, 31))
        icon4 = QtGui.QIcon()
        icon4.addPixmap(QtGui.QPixmap("icons/search.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
        self.tb_search.setIcon(icon4)
        self.tb_search.setIconSize(QtCore.QSize(32, 32))
        self.tb_search.setObjectName("tb_search")
        ############### Event #############################3
        self.tb_search.clicked.connect(self.search)
        #self.tb_search.returnPressed.connect(self.search)
        ##################################################

        self.webView = QtWebEngineWidgets.QWebEngineView(self.centralwidget) # + QWebEngineView

        self.webView.setGeometry(QtCore.QRect(0, 60, 1400, 700))
        self.webView.setUrl(QtCore.QUrl("about:blank"))
        self.webView.setObjectName("webView")
        MainWindow.setCentralWidget(self.centralwidget)

        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("PyxisAd", "PyxisAd"))
        self.tb_back.setText(_translate("PyxisAd", "back"))
        self.tb_reload.setText(_translate("PyxisAd", "reload"))
        self.tb_forword_2.setText(_translate("PyxisAd", "forword"))
        self.tb_home.setText(_translate("PyxisAd", "home"))
        self.tb_search.setText(_translate("PyxisAd", "search"))   


if __name__ == "__main__": 
    import sys 
    app = QtWidgets.QApplication(sys.argv) 
    MainWindow = QtWidgets.QMainWindow() 
    ui = Ui_MainWindow() 
    ui.setupUi(MainWindow) 
    MainWindow.show() 
    sys.exit(app.exec_())

0 个答案:

没有答案