【发布时间】:2017-01-04 04:59:04
【问题描述】:
我尝试了两种不同的方式在 PyQt 中加载和显示 SVG 文件:
import sys
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
app = QApplication(sys.argv)
webView = QWebEngineView()
# Variant 1: Reasonably fast
webView.load(QUrl('file:///Test.svg'))
# Variant 2: Slow for small files, not working for big ones
webView.setHtml('<svg>........')
webView.show()
sys.exit(app.exec_())
第一种方法可以,但需要一个文件作为输入。我想动态生成 SVG,所以这不是一个真正的选择。有谁知道为什么第二种方法对于更复杂的矢量图像如此缓慢或完全失败?
【问题讨论】:
-
你为什么不用QSvgWidget?
-
因为我使用 Javascript 进行一些 SVG 交互。
标签: python qt svg pyqt5 qtwebengine