S. Lancaster
S. Lancaster

Reputation: 53

How to tell if it is possible to go back/forward QWebEngineView

How do I tell if it is possible to go back/forward QWebEngineView?

I need to tell if there is a signal put out by qwebengine when it is possible to go back or go forward.

I am running Arch Linux with plasma 5.9 and python 3.6.0.

Upvotes: 0

Views: 562

Answers (1)

shao.lo
shao.lo

Reputation: 4626

The QWebEnginePage.WebActions can be used for this. The following example will load google, then 5 seconds later load bing. After another 5 seconds it will check the navigation actions. This would normally be done in your view's setPage(). The code below is just to demonstrate the API.

import sys
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
app = QtWidgets.QApplication(sys.argv)
w = QWebEngineView()
w.load(QtCore.QUrl('http://google.com'))

def _test_navigaion():
    w.load(QtCore.QUrl('http://bing.com'))
    QtCore.QTimer.singleShot(5000, _test_navigaion2)

def _test_navigaion2():
    print('back enabled', w.page().action(QWebEnginePage.Back).isEnabled())
    print('forward enabled', w.page().action(QWebEnginePage.Forward).isEnabled())
QtCore.QTimer.singleShot(5000, _test_navigaion)

w.show()
app.exec_()

Upvotes: 3

Related Questions