Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QPixmap and SVG

Tags:

svg

qt

qpixmap

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.

like image 950
Matthieu Riegler Avatar asked Apr 09 '12 19:04

Matthieu Riegler


3 Answers

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.

like image 87
Yash Avatar answered Nov 15 '22 17:11

Yash


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

like image 41
Troubadour Avatar answered Nov 15 '22 17:11

Troubadour


Something like that:

QSvgRenderer renderer(svg_file_name);
QPixmap pm(width, height);
pm.fill(fill_color);
QPainter painter(&pm);
renderer.render(&painter, pm.rect());
like image 26
Sergey Galin Avatar answered Nov 15 '22 18:11

Sergey Galin