I
I
Issue2020-02-12 05:28:04
Python
Issue, 2020-02-12 05:28:04

How to pass an address to a QWebView with a button?

I can't get the Go button to work in any way, it should pass the address from the url input directly to the page viewer:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWebKitWidgets import QWebView as W
from PyQt5.QtCore import QUrl as U

class Ui_w(object):
    def setupUi(s, w):
        w.setObjectName("w")
        w.resize(613, 409)
        s.body = QtWidgets.QWidget(w)
        s.body.setObjectName("body")
        s.div = QtWidgets.QGridLayout(s.body)
        s.div.setObjectName("div")
        s.url = QtWidgets.QLineEdit(s.body) # Это поле из которого взять URL
        s.url.setObjectName("url")
        s.div.addWidget(s.url, 0, 0, 1, 1)
        s.go = QtWidgets.QPushButton(s.body) # Кнопка которая должна передавать URL
        s.go.setObjectName("go")
        s.div.addWidget(s.go, 0, 1, 1, 1)
        s.web = W(s.body)
        s.web.setObjectName("web")
        s.div.addWidget(s.web, 1, 0, 1, 2)
        w.setCentralWidget(s.body)
        s.retranslateUi(w)
        QtCore.QMetaObject.connectSlotsByName(w)

    def retranslateUi(s, w):
        _translate = QtCore.QCoreApplication.translate
        w.setWindowTitle(_translate("w", "QWebView"))
        s.go.setText(_translate("w", "Search")) 
        s.web.load(U('https://google.com')) # Сюда нужно передать URL
        s.web.showMaximized()

if __name__ == "__main__":
    from sys import exit as e
    from sys import argv as v
    a = QtWidgets.QApplication(v)
    w = QtWidgets.QMainWindow()
    ui = Ui_w()
    ui.setupUi(w)
    w.show()
    e(a.exec_())

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question