<div style="line-height:1.7;color:#000000;font-size:14px;font-family:Arial"><!--StartFragment--><div><br></div><p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: "Titillium Web"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;"><em style="box-sizing: border-box;"><span>I </span>also posted the question<span> </span><a href="https://stackoverflow.com/questions/56619358/inject-code-to-webpage-using-qwebenginepagerunjavascript" rel="nofollow" style="box-sizing: border-box; background-color: transparent; color: rgb(51, 122, 183); text-decoration: none; -webkit-tap-highlight-color: transparent;">here</a>.</em></p><p style="box-sizing: border-box; margin: 0px 0px 10px; color: rgb(51, 51, 51); font-family: "Titillium Web"; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(255, 255, 255); text-decoration-style: initial; text-decoration-color: initial;">When QWebEngineView starts loading a web page , I want to inject<span> </span><a href="https://github.com/HubSpot/pace#example" rel="nofollow" style="box-sizing: border-box; background-color: transparent; color: rgb(51, 122, 183); text-decoration: none; -webkit-tap-highlight-color: transparent;">a web page progress bar</a><span> </span>to it, my code as the following , but I cannot see the progress bar during loading , so what's wrong ?</p><pre class="markdown-highlight" style="box-sizing: border-box; overflow: auto; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: 13px; display: block; padding: 9.5px; margin: 1rem 0px 10px; line-height: 1.42857; word-break: break-all; overflow-wrap: break-word; color: rgb(51, 51, 51); background-color: rgb(255, 255, 255); border: none; border-radius: 0px; max-height: 350px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;"><code class="hljs python" style="box-sizing: border-box; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; font-size: inherit; padding: 0.5em; color: black; background: white; border-radius: 0px; white-space: pre; display: inline-block; overflow-x: auto; overflow-wrap: normal; min-width: 100%;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> sys
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> PyQt5.QtWidgets <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> *
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> PyQt5.QtWebEngineWidgets <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> *
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> PyQt5.QtWebEngineCore <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> *
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">from</span> PyQt5.QtCore <span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">import</span> *
<span class="hljs-class" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">class</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">WebEngineView</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(QWebEngineView)</span>:</span>
<span class="hljs-function" style="box-sizing: border-box;"><span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">def</span> <span class="hljs-title" style="box-sizing: border-box; color: rgb(102, 0, 102);">__init__</span><span class="hljs-params" style="box-sizing: border-box; color: rgb(102, 0, 102);">(self, parent=None)</span>:</span>
super().__init__(parent)
self.webPage = self.page()
self.webPage.runJavaScript(<span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">'''
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);
'''</span>)
self.webPage.load(QUrl(<span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">'https://doc.qt.io/qt-5/qwebenginepage.html'</span>))
<span class="hljs-keyword" style="box-sizing: border-box; color: rgb(0, 0, 136);">if</span> __name__ == <span class="hljs-string" style="box-sizing: border-box; color: rgb(0, 136, 0);">"__main__"</span>:
app = QApplication(sys.argv)
app.setAttribute(Qt.AA_UseSoftwareOpenGL)
webEngineView = WebEngineView()
webEngineView.show()
sys.exit(app.exec_())</code></pre><!--EndFragment--></div><br><br><span title="neteasefooter"><p> </p></span>