qwebenginepage pyqt5 code example
Example: how to use qwebengineview in pyqt5
from PyQt5.QtCore import QUrl
from PyQt5.QtWidgets import QMainWindow, QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from flask import Flask, render_template, request
import threading
import sys
class MainWindow(QMainWindow):
def __init__(self, *args, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
self.setWindowTitle("Sorted Ware House")
self.setMinimumSize(900, 550)
self.browser = QWebEngineView()
self.browser.setUrl(QUrl("http://127.0.0.1:5000"))
self.setCentralWidget(self.browser)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
app_ = Flask(__name__)
@app_.route('/')
def index():
return render_template('index.html')
kwargs = {'host': '127.0.0.1', 'port': 5000 , 'threaded' : True, 'use_reloader': False, 'debug':False}
t1 = threading.Thread(target=app_.run, daemon = True, kwargs=kwargs).start()
app.exec_()