how to use qwebengineview in pyqt5

Solutions on MaxInterview for how to use qwebengineview in pyqt5 by the best coders in the world

showing results for - "how to use qwebengineview in pyqt5"
Leni
30 May 2016
1from PyQt5.QtCore import QUrl
2from PyQt5.QtWidgets import QMainWindow, QApplication
3from PyQt5.QtWebEngineWidgets import QWebEngineView
4from flask import Flask, render_template, request
5
6import threading
7import sys
8
9# You can copy past this code and run it
10# Just change the index.html to your html file
11
12class MainWindow(QMainWindow):
13    # In here i've set the QWebEngineView as CentralWidget
14    # You can use a layout to position it where you want
15    def __init__(self, *args, **kwargs):
16        super(MainWindow, self).__init__(*args, **kwargs)
17
18        self.setWindowTitle("Sorted Ware House")
19        self.setMinimumSize(900, 550)
20
21        self.browser = QWebEngineView() # create web view
22        self.browser.setUrl(QUrl("http://127.0.0.1:5000")) # set root
23        self.setCentralWidget(self.browser) # place it in QMainWindow
24
25if __name__ == "__main__":
26    app = QApplication(sys.argv)
27    window = MainWindow()
28    window.show()
29
30    app_ = Flask(__name__)
31    @app_.route('/')
32    def index():
33        return render_template('index.html')
34    kwargs = {'host': '127.0.0.1', 'port': 5000 , 'threaded' : True, 'use_reloader': False, 'debug':False}
35    t1 = threading.Thread(target=app_.run, daemon = True, kwargs=kwargs).start()
36
37    app.exec_()
38# For smooth scrolling add '--enable-smooth-scrolling' parameter when
39#  running the app as your app's argument.
40# like : python app.py --enable-smooth-scrolling
41