QWebView 可以从 Qt 资源文件加载图像吗? [英] Can QWebView load images from Qt resource files?

查看:50
本文介绍了QWebView 可以从 Qt 资源文件加载图像吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Qt 应用程序的资源文件(用于帮助系统)中捆绑了一些 HTML 和 PNG.不幸的是,我找不到 HTML 显示图像的方法.我已经尝试了 QWebView 的基本 URL 和 <img> 标记的不同 URL 的各种组合,但到目前为止都没有奏效.

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, ???);

这可能吗?

推荐答案

试试你的资源格式:

qrc:/resources/cat.png

代替

:/resources/cat.png

我们有 .css 文件,它们在 webview 中使用这种格式的图像,并且工作正常

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

这篇关于QWebView 可以从 Qt 资源文件加载图像吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆