class FormWidget(QWidget): def __init__(self, parent): super(FormWidget, self).__init__(parent) self.__controls() self.__layout() def __controls(self): path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test2.html") print(path) #html = open('test2.html', 'r').read() self.browser = QWebEngineView() self.browser.setPage(WebPage(self.browser)) #self.browser.load(QUrl.fromLocalFile(path)) self.browser.load(QUrl("http://localhost:5000")) #//self.browser.setHtml(") #self.browser.loadFinished.connect(self.onLoadFinished) """ def onLoadFinished(self, ok): pass #if ok: # #self.browser.page().runJavaScript("helloWorld(1, \"2\")", self.ready) """ def __layout(self): self.vbox = QVBoxLayout() self.hBox = QVBoxLayout() self.hBox.addWidget(self.browser) self.vbox.addLayout(self.hBox) self.setLayout(self.vbox) def ready(self, returnValue): print(returnValue)
def __init__(self, filename, parent=None): super(LocationWidget, self).__init__(parent) self.temp_dir = QTemporaryDir() if self.temp_dir.isValid(): with exiftool.ExifTool(exiftool_exe()) as et: try: metadata = et.get_metadata(filename) lat = metadata["Composite:GPSLatitude"] lon = metadata["Composite:GPSLongitude"] except KeyError: label = QLabel(self.tr("Geolocation data not found!")) modify_font(label, bold=True) label.setStyleSheet("color: #FF0000") label.setAlignment(Qt.AlignCenter) layout = QVBoxLayout() layout.addWidget(label) self.setLayout(layout) return url = f"https://www.google.com/maps/place/{lat},{lon}/@{lat},{lon},17z/" \ f"data=!4m5!3m4!1s0x0:0x0!8m2!3d{lat}!4d{lon}" web_view = QWebEngineView() web_view.load(QUrl(url)) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout)
def webkit_download(url): app = QApplication([]) webview = QWebEngineView() webview.loadFinished.connect(app.quit) webview.load(url) app.exec_() # delay here until download finished return webview.page().mainFrame().toHtml()
def __init__(self, parent=None): super(EditorWidget, self).__init__(parent) web_view = QWebEngineView() web_view.load(QUrl('https://hexed.it/')) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout)
class HelpWindow(QMainWindow): def __init__(self, parent=None): super(HelpWindow,self).__init__(parent) self.setWindowTitle("Facepager 3.0 - Help") self.setMinimumWidth(600); self.setMinimumHeight(600); central = QWidget() self.setCentralWidget(central) vLayout = QVBoxLayout(central) self.page = MyQWebEnginePage() self.browser = QWebEngineView(central) self.browser.setPage(self.page) vLayout.addWidget(self.browser) hLayout = QHBoxLayout() vLayout.addLayout(hLayout) hLayout.addStretch(5) dismiss = QPushButton(central) dismiss.setText("Close") dismiss.clicked.connect(self.hide) hLayout.addWidget(dismiss) #browser.setBackgroundRole(QPalette.Window) def show(self): super(HelpWindow,self).show() self.loadPage() def loadPage(self): self.browser.load(QUrl("http://strohne.github.io/Facepager/"))
class MainWindow(QMainWindow): view = None chan = None comm = None def __init__(self, debug=False, parent=None): QMainWindow.__init__(self, parent) QWebEngineSettings.defaultSettings().setAttribute( QWebEngineSettings.JavascriptCanAccessClipboard, True) QWebEngineSettings.defaultSettings().setAttribute( QWebEngineSettings.JavascriptCanPaste, True) self.view = QWebEngineView(self) self.setCentralWidget(self.view) self.chan = QWebChannel(self) self.comm = Comm(self) self.chan.registerObject('channelInterface', self.comm) self.view.page().setWebChannel(self.chan) self.view.setContextMenuPolicy(Qt.NoContextMenu) if debug: self.view.load('http://localhost:8080') self.devView = QWebEngineView() self.view.page().setDevToolsPage(self.devView.page()) self.devView.show() else: url = 'file:///' + QDir.fromNativeSeparators( os.path.abspath( os.path.join(os.path.dirname(__file__), './frontend/dist/index.html'))) self.view.load(QUrl(url))
def main(): app = QApplication(sys.argv) #shared= QSharedMemory("wepush") #if shared.attach(): #return 0 #shared.create(1) #sys.stdout=common.Mystd() loop = QEventLoop(app) asyncio.set_event_loop(loop) win = QWebEngineView() # QWebEngineView() director['root_win'] = win #thread.start_new_thread (server.start_server,(28289,)) #win =QWebView() #win.setWindowIcon(QIcon( './html/wechat.ico')) win.setMinimumSize(1200, 900) win.setWindowTitle('微信群发工具V1.0') url = 'file:///%s/test.html' % base_dir.replace('\\', '/') win.load(QUrl(url)) win.show() with loop: from server import start_server #loop.set_debug(True) loop.run_until_complete(start_server) #loop.create_task(send()) #loop.create_task(start_server) loop.run_forever()
class Form(QObject): def __init__(self, ui_file, parent=None): super(Form, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(ui_file) ui_file.close() self.host = self.window.findChild(QLineEdit, 'userText') self.pw = self.window.findChild(QLineEdit, 'passwordText') btn = self.window.findChild(QPushButton, 'submitButton') btn.clicked.connect(self.button_handler) self.window.show() def loadMap(self): print("load map here!") self.browser = QWebEngineView() self.browser.load(QUrl('https://www.google.com/maps')) self.browser.show() def button_handler(self): if self.host.text() == "host" and self.pw.text() == "pass": print('Success!') self.loadMap() else: print('Invalid login!')
def __init__(self, filename, parent=None): super(LocationWidget, self).__init__(parent) self.temp_dir = QTemporaryDir() if self.temp_dir.isValid(): with exiftool.ExifTool(exiftool_exe()) as et: temp_file = os.path.join(self.temp_dir.path(), "geo.html") metadata = et.get_metadata(filename) try: lat = metadata["Composite:GPSLatitude"] long = metadata["Composite:GPSLongitude"] except KeyError: label = QLabel(self.tr("Geolocation data not found!")) modify_font(label, bold=True) label.setStyleSheet("color: #FF0000") label.setAlignment(Qt.AlignCenter) layout = QVBoxLayout() layout.addWidget(label) self.setLayout(layout) return html = '<iframe src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2948.532014673314!2d{}!3d{}!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0x0!2zNDLCsDIxJzA5LjAiTiA3McKwMDUnMjguMiJX!5e0!3m2!1sit!2sit!4v1590074026898!5m2!1sit!2sit" width="600" height="450" frameborder="0" style="border:0;" allowfullscreen="" aria-hidden="false" tabindex="0"></iframe>'.format( long, lat) with open(temp_file, "w") as file: file.write(html) web_view = QWebEngineView() web_view.load(QUrl("file://" + temp_file)) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout)
def __init__(self, parent, name, view): QWidget.__init__(self, parent) DockContextHandler.__init__(self, self, name) layout = QGridLayout(self) webview = QWebEngineView() webview.load("https://cloud.binary.ninja") layout.addWidget(webview, 0, 0)
class PlotViewer(QWidget): feedPlotControls = Signal(str) def __init__(self): super().__init__() self.webView = QWebEngineView() layout = QGridLayout() layout.addWidget(self.webView, 0, 0) self.setLayout(layout) self.json_data = '' self.plot_type = 'Regressão' self.webView.page().profile().downloadRequested.connect(self.download_handler) def loadPlot(self, _url, _json=None, _type='Regressão'): assert(isinstance(_json, str)) #takes html local address to plot generated by plotly if _json is not None: self.json_data = _json self.feedPlotControls.emit(self.json_data) self.plot_type = _type url = QUrl.fromLocalFile(os.path.abspath(_url)) self.webView.load(url) def erasePlot(self): self.json_data = '' pcengine = PlotControleEngine.PlotControlEngine(self.json_data) _url, self.json_data = pcengine.render() url = QUrl.fromLocalFile((os.path.abspath(_url))) self.webView.load(url) def download_handler(self, item): file_path = QFileDialog().getSaveFileName(self, "Salvar Plot", filter="PNG (*.png);;") item.setPath(file_path[0]) item.accept()
class WebView(QtGui.QMdiSubWindow): closed = QtCore.Signal(object) def __init__(self, title, work_path, request_handler, message_handler, *args, **kwargs): # Window Setup super().__init__(*args, **kwargs) self.setObjectName("freecad.extman.webview") self.setWindowTitle(title) self.setAttribute(Qt.WA_DeleteOnClose, True) # Scheme setup (extman://) self.handler = SchemeHandler(self, request_handler) # WebView setup self.webView = QWebEngineView(self) self.webView.setContextMenuPolicy(Qt.NoContextMenu) self.setWidget(self.webView) # Page setup self.webView.setPage(Page(self.webView)) # Profile setup profile = self.webView.page().profile() profile.setPersistentStoragePath(str(Path(work_path, 'web_data'))) profile.setCachePath(str(Path(work_path, 'web_cache'))) handler = profile.urlSchemeHandler(EXTMAN_URL_SCHEME) if handler is not None: profile.removeUrlSchemeHandler(handler) profile.installUrlSchemeHandler(EXTMAN_URL_SCHEME, self.handler) # Setting setup settings = self.webView.settings() settings.setAttribute(QWebEngineSettings.AutoLoadIconsForPage, True) settings.setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, True) settings.setAttribute( QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) # Page settings page = self.webView.page().settings() page.setAttribute(QWebEngineSettings.LocalContentCanAccessFileUrls, True) page.setAttribute(QWebEngineSettings.LocalContentCanAccessRemoteUrls, True) page.setAttribute(QWebEngineSettings.LocalStorageEnabled, True) # WebChannel Setup self.messageBus = MessageBus(message_handler, self.webView) self.channel = QtWebChannel.QWebChannel(self.webView) self.channel.registerObject('ExtManMessageBus', self.messageBus) self.webView.page().setWebChannel(self.channel) def closeEvent(self, event): self.closed.emit(event) event.accept() def load(self, url): self.webView.load(url)
class MaiteBody(QWidget): """Main display body""" def __init__(self): super().__init__(None) # main horizontal view hlay = QHBoxLayout() # left pane e1 = QLineEdit() hlay.addWidget(e1, 25) # right pane self.webEngineView = QWebEngineView() current_path = os.getcwd() fileLocation = current_path + "/reloj.html" print(fileLocation) url = QUrl.fromLocalFile(fileLocation) self.webPage = self.webEngineView.page() self.webEngineView.load(url) self.webEngineView.show() hlay.addWidget(self.webEngineView, 75) self.setLayout(hlay)
class MainTest(unittest.TestCase): def test_WebEngineView_findText_exists(self): QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) app = QApplication.instance() or QApplication() top_level = QWidget() layout = QVBoxLayout(top_level) self._view = QWebEngineView() self._view.loadFinished.connect(self.loaded) self._view.load(QUrl.fromLocalFile(os.path.join(TEST_DIR, "fox.html"))) self._view.setMinimumSize(QSize(400, 300)) self._callback_count = 0 layout.addWidget(self._view) top_level.show() app.exec_() def found_callback(self, found): self.assertTrue(found) self._callback_count += 1 if self._callback_count == 2: QCoreApplication.quit() def javascript_callback(self, result): self.assertEqual(result, "Title") self._callback_count += 1 if self._callback_count == 2: QCoreApplication.quit() def loaded(self, ok): self.assertTrue(ok) if not ok: QCoreApplication.quit() self._view.page().runJavaScript("document.title", 1, partial(self.javascript_callback)) self._view.findText("fox", QWebEnginePage.FindFlags(), partial(self.found_callback))
class HelpWindow(QMainWindow): def __init__(self, parent=None): super(HelpWindow, self).__init__(parent) self.setWindowTitle("Facepager 4.0 - Help") self.setMinimumWidth(600) self.setMinimumHeight(600) central = QWidget() self.setCentralWidget(central) vLayout = QVBoxLayout(central) self.page = MyQWebEnginePage() self.browser = QWebEngineView(central) self.browser.setPage(self.page) vLayout.addWidget(self.browser) hLayout = QHBoxLayout() vLayout.addLayout(hLayout) hLayout.addStretch(5) dismiss = QPushButton(central) dismiss.setText("Close") dismiss.clicked.connect(self.hide) hLayout.addWidget(dismiss) #browser.setBackgroundRole(QPalette.Window) def show(self): super(HelpWindow, self).show() self.loadPage() def loadPage(self): self.browser.load(QUrl("http://strohne.github.io/Facepager/"))
class TextMediaView(MediaView): def __init__(self, media, parent): super(TextMediaView, self).__init__(media, parent) self.widget = QWebEngineView(parent) self.widget.setGeometry(media['geometry']) self.set_default_widget_prop() self.widget.setDisabled(True) @Slot() def play(self): self.finished = 0 path = '%s/%s_%s_%s.html' % (self.save_dir, self.layout_id, self.region_id, self.id) self.widget.load('file:///' + path) self.widget.show() self.widget.raise_() if float(self.duration) > 0: self.play_timer.setInterval(int(float(self.duration) * 1000)) self.play_timer.start() self.started_signal.emit() @Slot() def stop(self, delete_widget=False): #---- kong ---- if not self.widget: return False super(TextMediaView, self).stop(delete_widget) return True
class WebMediaView_(MediaView): def __init__(self, media, parent): super(WebMediaView_, self).__init__(media, parent) self.widget = QWebEngineView(parent) self.widget.setGeometry(media['geometry']) self.set_default_widget_prop() self.widget.setDisabled(True) @Slot() def play(self): self.finished = 0 url = self.options['uri'] self.widget.load( QUrl.fromPercentEncoding(QByteArray(url.encode('utf-8')))) self.widget.show() self.widget.raise_() if float(self.duration) > 0: self.play_timer.setInterval(int(float(self.duration) * 1000)) self.play_timer.start() self.started_signal.emit() @Slot() def stop(self, delete_widget=False): #---- kong ---- if not self.widget: return False super(WebMediaView_, self).stop(delete_widget) return True
class Visual(QWidget): def __init__(self): super(Visual, self).__init__() self.browser = QWebEngineView() self.browser.load(QUrl("www.baidu.com")) layout = QVBoxLayout() layout.addWidget(self.browser) self.setLayout(layout)
class ReverseWidget(ToolWidget): def __init__(self, parent=None): super(ReverseWidget, self).__init__(parent) self.tineye_radio = QRadioButton(self.tr("TinEye")) self.tineye_radio.setIcon(QIcon("icons/tineye.png")) self.google_radio = QRadioButton(self.tr("Google")) self.google_radio.setIcon(QIcon("icons/google.svg")) self.bing_radio = QRadioButton(self.tr("Bing")) self.bing_radio.setIcon(QIcon("icons/bing.svg")) self.root_radio = QRadioButton(self.tr("RootAbout")) self.root_radio.setIcon(QIcon("icons/rootabout.png")) self.karma_radio = QRadioButton(self.tr("KarmaDecay")) self.karma_radio.setIcon(QIcon("icons/karmadecay.jpg")) self.tineye_radio.setChecked(True) self.last_radio = self.tineye_radio self.web_view = QWebEngineView() self.choose() self.tineye_radio.clicked.connect(self.choose) self.google_radio.clicked.connect(self.choose) self.bing_radio.clicked.connect(self.choose) self.root_radio.clicked.connect(self.choose) self.karma_radio.clicked.connect(self.choose) top_layout = QHBoxLayout() top_layout.addWidget(QLabel(self.tr("Search engine:"))) top_layout.addWidget(self.tineye_radio) top_layout.addWidget(self.google_radio) top_layout.addWidget(self.bing_radio) top_layout.addWidget(self.root_radio) top_layout.addWidget(self.karma_radio) top_layout.addStretch() main_layout = QVBoxLayout() main_layout.addLayout(top_layout) main_layout.addWidget(self.web_view) self.setLayout(main_layout) def choose(self): if self.tineye_radio.isChecked(): self.web_view.load(QUrl("https://tineye.com/")) self.last_radio = self.tineye_radio elif self.google_radio.isChecked(): self.web_view.load(QUrl("https://www.google.com/imghp")) self.last_radio = self.google_radio elif self.bing_radio.isChecked(): self.web_view.load( QUrl("https://www.bing.com/?scope=images&nr=1&FORM=NOFORM")) self.last_radio = self.bing_radio elif self.root_radio.isChecked(): self.web_view.load(QUrl("http://rootabout.com/")) self.last_radio = self.root_radio elif self.karma_radio.isChecked(): self.web_view.load(QUrl("http://karmadecay.com/")) self.last_radio = self.karma_radio else: self.last_radio.setChecked(True)
class ManualWindow(QMainWindow): def __init__(self): super(ManualWindow, self).__init__() self.setWindowTitle('QAX Manual') icon_info = QFileInfo(app_info.app_icon_path) self.setWindowIcon(QIcon(icon_info.absoluteFilePath())) self.toolbar = QToolBar() self.addToolBar(self.toolbar) self.back_button = QPushButton() self.back_button.setIcon(qta.icon('fa.arrow-left')) self.back_button.clicked.connect(self.back) self.toolbar.addWidget(self.back_button) self.forward_button = QPushButton() self.forward_button.setIcon(qta.icon('fa.arrow-right')) self.forward_button.clicked.connect(self.forward) self.toolbar.addWidget(self.forward_button) self.address_line_edit = QLineEdit() self.address_line_edit.returnPressed.connect(self.load) self.address_line_edit.setVisible(False) self.toolbar.addWidget(self.address_line_edit) self.web_engine_view = QWebEngineView() self.web_engine_view.setZoomFactor(2.0) self.setCentralWidget(self.web_engine_view) initialUrl = self.docs_url() self.address_line_edit.setText(str(initialUrl)) self.web_engine_view.load(QUrl(initialUrl)) self.web_engine_view.page().urlChanged.connect(self.urlChanged) def docs_url(self): rel_docs_path = 'docs/_build/html/index.html' abs_docs_oath = os.path.abspath(rel_docs_path) if (os.path.isfile(abs_docs_oath)): return QUrl.fromLocalFile(abs_docs_oath) raise RuntimeError("Docs not found at {}".format(abs_docs_oath)) def load(self): url = QUrl.fromUserInput(self.address_line_edit.text()) if url.isValid(): self.web_engine_view.load(url) def back(self): self.web_engine_view.page().triggerAction(QWebEnginePage.Back) def forward(self): self.web_engine_view.page().triggerAction(QWebEnginePage.Forward) def urlChanged(self, url): self.address_line_edit.setText(url.toString())
def test(): url = 'https://github.com/tody411/PyIntroduction' #QCoreApplication.setAttribute() app = QApplication(sys.argv) browser = QWebEngineView() browser.load(QUrl(url)) browser.resize(1024, 750) browser.show() sys.exit(app.exec_())
class MyWidget(QWidget): def __init__(self): QWidget.__init__(self) self.webView = QWebEngineView() self.webView.load("https://www.messenger.com/login") self.layout = QVBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.webView) self.setLayout(self.layout)
def show_help(): global web_view if web_view is not None: web_view.close() web_view = QWebEngineView() # paths need to be absolute, therefore calculate realtive to current file path = os.path.abspath( os.path.join(os.path.dirname(__file__), "Help_en.html")) url = QtCore.QUrl.fromLocalFile(path) web_view.load(url) web_view.setWindowTitle("Help") web_view.show()
def __init__(self, parent=None): super(Window, self).__init__(parent) layout = QtWidgets.QVBoxLayout() view = QWebEngineView() layout.addWidget(view) self.setLayout(layout) self.resize(900, 600) url = 'file://' + os.path.join( pathlib.Path(__file__).parent.absolute(), 'index.html') print(url) view.load(QUrl(url))
def test_SchemeHandlerRedirect(self): app = QApplication([]) handler = TestSchemeHandler() profile = QWebEngineProfile.defaultProfile() profile.installUrlSchemeHandler("testpy", handler) view = QWebEngineView() view.loadFinished.connect(app.quit) QTimer.singleShot(5000, app.quit) view.show() view.load("testpy:hello") app.exec_() self.assertEqual(view.url(), "testpy:goodbye")
class MainWindow(QMainWindow): def __init__(self, td: ameritrade.AmeritradeAPI): super(MainWindow, self).__init__() self.td = td self.setWindowTitle('Charting widget') # A web view for the chart. # TODO(blais): Replace this by a custom view, not web. self.webEngineView = QWebEngineView() # A text input for selection an expression to render. self.instrumentEdit = QLineEdit() self.instrumentEdit.returnPressed.connect(self.update_query) # Layout for main portion of the screen. layout = QVBoxLayout() layout.addWidget(self.webEngineView) layout.addWidget(self.instrumentEdit) widget = QWidget(self) widget.setLayout(layout) self.setCentralWidget(widget) def update_query(self): query = self.instrumentEdit.text() # Handle the case of an empty input. if not query: self.webEngineView.setHtml('') return # Open the template and make all src references absolute to this # directory. with open(template_filename) as template_file: template = template_file.read() template = re.sub('src="', f'src="file://{this_dir}/', template) # Fetch the data. data = get_pricing_data(self.td, query) if data is None: logging.error(f'Failed to retrieve data for "{query}"') return template = template.replace("DATA", data) # Note that the setHtml() method or setContent() do not work as # expected; loading jQuery or other libraries from within will fail, # even with the baseUrl provided. I'm resorting to a temporary file for # this reason. self.htmlfile = tempfile.NamedTemporaryFile(suffix='.html', mode='w') self.htmlfile.write(template) url = "file://{}".format(self.htmlfile.name) self.webEngineView.load(url)
def create(ui_path, proxy): view = QWebEngineView() page = view.page() channel = QWebChannel() channel.registerObject('hatPegBrowserProxy', proxy) page.setWebChannel(channel) view.load(str((ui_path / 'index.html').resolve().as_uri())) view.show() _refs[view] = (channel, proxy)
def __init__(self, filename, parent=None): super(StructureWidget, self).__init__(parent) self.temp_dir = QTemporaryDir() if self.temp_dir.isValid(): temp_file = os.path.join(self.temp_dir.path(), 'structure.html') p = run([exiftool_exe(), '-htmldump0', filename], stdout=PIPE) with open(temp_file, 'w') as file: file.write(p.stdout.decode('utf-8')) web_view = QWebEngineView() web_view.load(QUrl('file://' + temp_file)) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout)
class HelpContentWindow(QWidget): def __init__(self): super().__init__() self.setWindowTitle('Ayuda de la aplicación de cobro de Clean Market') self.navegador = QWebEngineView() vbox = QVBoxLayout() vbox.addWidget(self.navegador) self.setLayout(vbox) def display_help(self): file_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '../static/html/help.html')) local_url = QUrl.fromLocalFile(file_path) self.navegador.load(local_url) self.showMaximized()
def __init__(self, filename, parent=None): super(HeaderWidget, self).__init__(parent) self.temp_dir = QTemporaryDir() if self.temp_dir.isValid(): temp_file = os.path.join(self.temp_dir.path(), "structure.html") p = run([exiftool_exe(), "-htmldump0", filename], stdout=PIPE) with open(temp_file, "w") as file: file.write(p.stdout.decode("utf-8")) web_view = QWebEngineView() web_view.load(QUrl("file://" + temp_file)) layout = QVBoxLayout() layout.addWidget(web_view) self.setLayout(layout) self.setMinimumWidth(900)
class ContentInnerWidget(QWidget): def __init__(self, container): QWidget.__init__(self, container) PageSignal.changed.connect(self.render) self.view = QWebEngineView() self.layout = QVBoxLayout() self.layout.setContentsMargins(0, 0, 0, 0) self.layout.addWidget(self.view) self.setLayout(self.layout) def render(self, url): self.view.load(QUrl(url)) self.view.show()
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.setWindowTitle('PySide2 WebEngineWidgets Example') self.toolBar = QToolBar() self.addToolBar(self.toolBar) self.backButton = QPushButton() self.backButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/left-32.png')) self.backButton.clicked.connect(self.back) self.toolBar.addWidget(self.backButton) self.forwardButton = QPushButton() self.forwardButton.setIcon(QIcon(':/qt-project.org/styles/commonstyle/images/right-32.png')) self.forwardButton.clicked.connect(self.forward) self.toolBar.addWidget(self.forwardButton) self.addressLineEdit = QLineEdit() self.addressLineEdit.returnPressed.connect(self.load) self.toolBar.addWidget(self.addressLineEdit) self.webEngineView = QWebEngineView() self.setCentralWidget(self.webEngineView) initialUrl = 'http://qt.io' self.addressLineEdit.setText(initialUrl) self.webEngineView.load(QUrl(initialUrl)) self.webEngineView.page().titleChanged.connect(self.setWindowTitle) self.webEngineView.page().urlChanged.connect(self.urlChanged) def load(self): url = QUrl.fromUserInput(self.addressLineEdit.text()) if url.isValid(): self.webEngineView.load(url) def back(self): self.webEngineView.page().triggerAction(QWebEnginePage.Back) def forward(self): self.webEngineView.page().triggerAction(QWebEnginePage.Forward) def urlChanged(self, url): self.addressLineEdit.setText(url.toString())