QPixmap and SVG

2019-04-13 02:42发布

How would you suggest to handle svg with QPixmap?

The construct QPixmap(":/myfile.svg"); then call of scaled() does not work. The QPixmap gets pixelised.

Thx.

标签: qt svg qpixmap
3条回答
SAY GOODBYE
2楼-- · 2019-04-13 02:50

Something like that:

QSvgRenderer renderer(svg_file_name);
QPixmap pm(width, height);
pm.fill(fill_color);
QPainter painter(&pm);
renderer.render(&painter, pm.rect());
查看更多
倾城 Initia
3楼-- · 2019-04-13 02:54

Now there is much simpler way without needing of SVG module

QIcon("filepath.svg").pixmap(QSize())

So simple and works fine. Atleast in my case it worked.

查看更多
forever°为你锁心
4楼-- · 2019-04-13 03:12

You should use SVGRenderer to render it onto a QImage. From there you can convert to a QPixmap with QPixmap::convertFromImage.

查看更多
登录 后发表回答