MCPcopy Index your code
hub / github.com/PyQt5/PyQt / loadResource

Method loadResource

QTextBrowser/DynamicRes.py:41–60  ·  view source on GitHub ↗
(self, rtype, url)

Source from the content-addressed store, hash-verified

39 self.NetImages[url] = [QByteArray(), 1]
40
41 def loadResource(self, rtype, url):
42 ret = super(TextBrowser, self).loadResource(rtype, url)
43 # 加载图片资源
44 if rtype == QTextDocument.ImageResource:
45 if ret:
46 return ret
47 if url.toString().startswith('irony'): # 自定义的协议头
48 print('加载本地', '../Donate/zhifubao.png', url)
49 return QImage(
50 '../Donate/zhifubao.png') # 或者 QByteArray(open('../Donate/zhifubao.png', 'rb').read())
51 elif url.toString().startswith('http'): # 加载网络图片
52 img, status = self.NetImages.get(url, [None, None])
53 if url not in self.NetImages or status is None:
54 # 子线程下载
55 self.NetImages[url] = [None, 1]
56 print('download ', url)
57 Thread(target=self.downloadImage, args=(url,), daemon=True).start()
58 elif img:
59 return img
60 return ret
61
62 def mouseDoubleClickEvent(self, event):
63 # 双击图片得到图片的URL,也可以用来放大显示

Callers

nothing calls this directly

Calls 2

ThreadClass · 0.50
startMethod · 0.45

Tested by

no test coverage detected