inject code to webpage using QWebEnginePage::runJavaScript()

"Zhao Lee" <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <[email protected]>


I also posted the question here.

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 *


classWebEngineView(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_())

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.