View Full Version : QSvgRenderer antialiasing

13th August 2009, 07:28

I'm trying to write an SVG out to a QPicture and antialias the image while doing so.
Here's my code.

However, when I render the QPicture (m_picture), it is aliased...as if the renderhints were ignored.
Is this expected behavior, or am I doing something wrong?

QSvgRenderer* m_renderer = getSvgResource(":/filesystem/file.svg");
QPainter imagePainter(&m_picture);
imagePainter.setRenderHints(QPainter::Antialiasing |QPainter::SmoothPixmapTransform, true);
QSvgRenderer* m_renderer->render(&imagePainter, m_bounds);

16th August 2009, 11:01
Very strange because the opposite should be hardcoded:


17th August 2009, 05:37
Yes it is very strange.

The QPicture is eventually draw to screen during a a call to QGraphicsItem:: paint
(it's drawn using painter->drawPicture(0,0, m_picture);

The image is not resized/modified at all between the creation code and the QGraphicsItem:: paint code.

Here's the result of the painting m_picture compared to google chrome.
- Obviously I've composited the images into one here.

Note: in this image, the Qt draws QPicture is supposed to be smaller than the one in Chrome (I didn't have time to make them the same size for this demo) - the QT drawn QPicture was NOT resized/scaled/filtered by my code at all.

Elsewhere in my code the very same QPicture is used in a different context: I also render the QPicture in to a QPixmap for use by QDrag (i.e QDrag::setPixmap).
I have just noticed that when I do this, the image is NOT antialised.

So, in summary - here are the two paths the SVG takes through my app:

SVG file --> QSvgRenderer --> QPicture --> painted into off screen context QPixmap by QGraphicsItem:: paint --> displayed by QDrag == Antialiased (good)

SVG file --> QSvgRenderer --> QPicture --> painted into screen context by QGraphicsItem:: paint == Aliased (bad)

17th August 2009, 07:30
OK I nailed it - QPainter::drawPicture is causing the problem.
If I convert the QPicture to a QPixmap, then the resultant image dawn by QPainter::drawPixmap is antialiased.

I have no idea why though

19th July 2013, 10:39

Sorry but I will bump this issue. I am having the same problem as jonks had. He gave an explanation in his last post but I couldn't get it working. How can I render anti-aliased svg image? Desperately looking for your helps & comments.

Thank you very much,