I\'m looking for a simple and reliable way for inserting an SVG image in a PyQt window. More precisely, I\'m wondering if it\'s possible to have an SVG image applied to a QLabel
QLabel
only can load a pixmap. If You need a vector-graphic use QtSvg.QSvgWidget()
and load the svg-file without converting:
import sys
from PyQt4 import QtGui, QtSvg
app = QtGui.QApplication(sys.argv)
svgWidget = QtSvg.QSvgWidget('Zeichen_123.svg')
svgWidget.setGeometry(50,50,759,668)
svgWidget.show()
sys.exit(app.exec_())
or render to any subclass of QPaintDevice
by QtSvg.QSvgRenderer
directly, e.g. to QLabel
:
app = QtGui.QApplication(sys.argv)
widget = QtGui.QLabel()
widget.setGeometry(50,200,500,500)
renderer = QtSvg.QSvgRenderer('Zeichen_123.svg')
widget.resize(renderer.defaultSize())
painter = QtGui.QPainter(widget)
painter.restore()
renderer.render(painter)
widget.show()
sys.exit(app.exec_())
get Zeichen_123.svg here