Can QWebView load images from Qt resource files?
Asked Answered
S

1

9

I've bundled some HTML and PNGs in my Qt app's resources file (for the help system). Unfortunately I can't find a way for the HTML to display images. I've tried various combinations of the QWebView's base URL, and different URLs for the <img> tag but none have worked so far.

To be clear, I want to be able to do something like this:

QString html = "<html><img href=':/resources/cat.png'/></html>";
myWebView->setHtml(html, ???);

Is this possible?

Surtax answered 3/3, 2013 at 15:37 Comment(1)
You probably want to set the imgage's src instead of it's href.Doone
E
20

Try your resource format as:

qrc:/resources/cat.png

instead of

:/resources/cat.png

we have .css files that use images in such a format within webview and it works fine

Exotoxin answered 3/3, 2013 at 17:18 Comment(1)
Perfect! Exactly what I was looking for (and I must have tried everything except that, qrc://, qrc:///, :/, etc). Thanks!Surtax

© 2022 - 2024 — McMap. All rights reserved.