On Mon, 25 Feb 2019 at 19:18, Felix Rubio Dalmau via Interest
<interest@qt-project.org> wrote:
>
> Hi all,
>
>         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()
>                 self.target.setPos(-rect.width()/2, -rect.height()/2)
>                 self.addItem(self.target)
>
>         So that then in my main window I set the QGraphicsView to do a 
> fitInView (the size of the widget is 500x500), via
>
>                 self.ui.targetView.fitInView(self.scene.sceneRect(), 
> QtCore.Qt.KeepAspectRatio)
>
>         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.renderer.render(self.painter)
>                 self.setBackgroundBrush(QtGui.QBrush(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?

Maybe you have a caching issue, see
https://doc.qt.io/qt-5/qgraphicsview.html#cacheMode-prop
Maybe as well https://doc.qt.io/qt-5/qgraphicsscene.html#invalidate could help

Chris

>
>         Thank you for your help!
>         Felix
>
>         PS: for reference, the picture is 
> https://upload.wikimedia.org/wikipedia/commons/1/17/WA_80_cm_archery_target.svg
>
>
> _______________________________________________
> Interest mailing list
> Interest@qt-project.org
> https://lists.qt-project.org/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
https://lists.qt-project.org/listinfo/interest

Reply via email to