View Single Post
Old 01-02-2025, 08:25 AM   #563
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
Posts: 8,895
Karma: 6120478
Join Date: Nov 2009
Device: many
Do *not* use setHtml as you are loading xhtml which is a different specification with very different parsing rules that are much less forgiving than the html spaghetti.

Use:

void setContent(const QByteArray &data, const QString &mimeType = QString(), const QUrl &baseUrl = QUrl())


The baseURL is the path to the file as a QUrl, and data holds the contents of the file in bytes (ie. a bytes buffer that you read the entire file into), and of course the proper mimetype: = "application/xhtml+xml"

See the QtWebEngineView online docs:

https://doc.qt.io/qt-6/qwebengineview.html

And for a python example see the calibre source code here:

https://github.com/kovidgoyal/calibr...lay/webview.py

Code:
    if force_as_html or load_as_html(html):
        view.setHtml(html, loading_url)
    else:
        view.setContent(QByteArray(html.encode(codec)), mime_type,
                loading_url)
        mf = view.page().mainFrame()
        elem = mf.findFirstElement('parsererror')

Last edited by KevinH; 01-02-2025 at 10:54 AM.
KevinH is offline   Reply With Quote