[Interest] Scaling out of SVG in QGraphicsScene background
Felix Rubio Dalmau
felix at kngnt.org
Mon Feb 25 07:18:12 CET 2019
I am trying to paint a SVG I have on a file on the background of a QGraphicsScene, and I am facing some issues: if I subclass QGraphicsScene and in the __init__ method I add:
self.target = QtSvg.QGraphicsSvgItem(target)
rect = self.target.boundingRect()
So that then in my main window I set the QGraphicsView to do a fitInView (the size of the widget is 500x500), via
The result is what expected: a nice, smooth image.
However, if I try to draw the SVG on the background of the QGraphicsScene, via:
self.renderer = QtSvg.QSvgRenderer(target)
rect = self.renderer.defaultSize()
self.image = QtGui.QImage(rect, QtGui.QImage.Format_ARGB32)
self.painter = QtGui.QPainter(self.image)
self.setSceneRect(QtCore.QRectF(QtCore.QPointF(0, 0), QtCore.QSizeF(self.image.size())))
Without doing the scaling the picture looks OK, but after doing the scaling the picture looks pixelized. How can I fix that?
Also, I have observed that I have to set the scene rectangle, while I understood that the scene itself would take care of that?
Thank you for your help!
PS: for reference, the picture is https://upload.wikimedia.org/wikipedia/commons/1/17/WA_80_cm_archery_target.svg
More information about the Interest