问题
When QWebEngineView starts loading a web page , I want to inject a web page progress bar to it, my code as the following , but I cannot see the progress bar during loading , so what's wrong ?
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtWebEngineWidgets import *
from PyQt5.QtWebEngineCore import *
from PyQt5.QtCore import *
class WebEngineView(QWebEngineView):
def __init__(self, parent=None):
super().__init__(parent)
self.webPage = self.page()
self.webPage.runJavaScript('''
var script = document.createElement('script');
var link = document.createElement('link');
script.type = 'text/javascript';
script.src = 'static/pace/pace.min.js';
link.rel = 'stylesheet';
link.href = 'static/pace/pace-theme-barber-shop.css';
document.head.appendChild(script);
document.head.appendChild(link);
''')
self.webPage.load(QUrl('https://doc.qt.io/qt-5/qwebenginepage.html'))
if __name__ == "__main__":
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_UseSoftwareOpenGL)
webEngineView = WebEngineView()
webEngineView.show()
sys.exit(app.exec_())
来源:https://stackoverflow.com/questions/56619358/inject-code-to-webpage-using-qwebenginepagerunjavascript