1

So in PyQt4 you could do something like this to append html to your page:

webView.page().mainFrame().documentElement().appendInside(some_html)

I was trying to find similar functionality in PyQt5's QWebEngineView but i couldn't find anything useful.

My problem is that i want to load many html files on one page, and it takes like 10 seconds to do that(means that main GUI thread is blocked during that 10 seconds, and my application is unresponsive).

So my solution was to display first 5, and when user presses the button, it loads next 5(with technique described above), and so on.

So my question is: Does QWebEngineView has this functionality, and is there some other way to deal with big or many html files in QWebEngineView.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
sup
  • 323
  • 1
  • 12

1 Answers1

1

documentElement() is a QWebElement and according to the docs is not available in Qt WebEngine.

The documentation recommends using javascript to replace this type of tasks, for example the following code adds html to the QwebEngineView:

import sys

from PyQt5.QtWidgets import QApplication
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtCore import QTimer, QDateTime

html = '''
<html>
<header><title>This is title</title></header>
<body>
Hello world
</body>
</html>
'''

def append():
    some_html = "<p>{}</p>".format(QDateTime.currentDateTime().toString())
    page.runJavaScript("document.body.innerHTML += '{}'".format(some_html))

app = QApplication(sys.argv)
view = QWebEngineView()
timer = QTimer()
timer.timeout.connect(append)
page = view.page()
page.loadFinished.connect(lambda: timer.start(1000))
page.setHtml(html)
view.show()
sys.exit(app.exec_())
eyllanesc
  • 235,170
  • 19
  • 170
  • 241