PyQt/QTextBrowser/README.md
2020-06-03 11:28:35 +08:00

14 lines
No EOL
659 B
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# QTextBrowser
- 目录
- [动态加载图片](#1动态加载图片)
## 1、动态加载图片
[运行 DynamicRes.py](DynamicRes.py)
动态加载资源有多种方式,这里主要介绍 [addResource](https://doc.qt.io/qt-5/qtextdocument.html#addResource) 和 [loadResource](https://doc.qt.io/qt-5/qtextbrowser.html#loadResource) 函数
1、通过 `self.textBrowser.document().addResource(QTextDocument.ImageResource, QUrl('dynamic:/images/weixin.png'), img)` 向文档中注册新的资源索引类似QRC
2、通过重载 `loadResource` 函数可以监听到所有的资源加载,然后动态返回内容
![DynamicRes](ScreenShot/DynamicRes.gif)