这张SVG图像在火狐和Inkscape中正确呈现,但由于某种原因,当使用QGraphicsSVGItem时没有任何花哨,它呈现如下方式:

作为参考,这是firefox上的样子:

如你所见,卡片的背面不应该越过白色的边框。
我做错了什么吗?有(最好容易)的修复吗?
MWE:
import sys
from PyQt5 import QtWidgets, QtCore, Qt, QtGui
app = QtWidgets.QApplication(sys.argv)
scene = QtWidgets.QGraphicsScene()
scene.addItem(Qt.QGraphicsSvgItem("back-red.svg"))
graphics_view = QtWidgets.QGraphicsView()
graphics_view.setScene(scene)
graphics_view.show()
sys.exit(app.exec())发布于 2020-05-26 23:23:28
您的svg可能不符合Qt使用的特性(有关更多信息,请阅读这里)。一个可能的解决方案是使用QWebEngineView(python -m pip install pyqtwebengine):
import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets, QtSvg, QtWebEngineWidgets
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
filename = os.path.join(CURRENT_DIR, "back-red.svg")
scene = QtWidgets.QGraphicsScene()
renderer = QtSvg.QSvgRenderer(filename)
graphics_view = QtWidgets.QGraphicsView()
graphics_view.setScene(scene)
graphics_view.show()
view = QtWebEngineWidgets.QWebEngineView()
view.setContextMenuPolicy(QtCore.Qt.NoContextMenu)
# view.page().setBackgroundColor(QtGui.QColor("transparent"))
view.resize(renderer.viewBox().size())
view.load(QtCore.QUrl.fromLocalFile(filename))
item = scene.addWidget(view)
graphics_view.resize(640, 480)
sys.exit(app.exec())https://stackoverflow.com/questions/62031161
复制相似问题