PDA

View Full Version : Vector graphic to QPainterPath



alitoh
9th August 2012, 19:14
This is a doubt I got from checking the Vector Deformation Demo (http://doc.qt.nokia.com/4.7-snapshot/demos-deform.html). Can I load a vector image and then copy it to a QPainterPath variable?

I wish to "extend" the demonstration to vector images, not just the text in the textbox, but I just don't seem to understand how.

I am guessing there is some correlation both because of the documentation and because the fonts themselves are vectors, and the principle should be about the same for applying either the text or the vector image the deformation effect.

So, is there a way to load an SVG (or any other vector file extension) and use that in the Vector Deformation Demo?

This is a doubt that got generated while I was playing around with the QT Demos in my spare time, so my only source files are the Demo Projects themselves, hence I got nothing to provide you on that part.

Any input is appreciated.

For reference, let's just pretend the image I am trying to import into the demo is this one (http://upload.wikimedia.org/wikipedia/commons/a/aa/VectorBitmapExample.svg).

d_stranz
10th August 2012, 16:30
I do not see any direct way of producing a QPainterPath instance from an SVG file. I would first start by taking a look at the QSvgRenderer::load() method to see what happens during the parsing of the SVG file. It might create a QPainterPath in that code (I don't know, I haven't looked, but it seems like a logical thing to do). If it does, then you can adapt that code for use in th edemo; if not, maybe you will find some clues.

Edit - Nope, QSvgRenderer does not use QPainterPath, it uses an internal data structure called "QSvgTinyDocument", which contains "QSvgNode" elements that appear to map to the same kinds of graphical elements that can be incorporated into QPainterPath. For example, the QSvgCircle::draw() method simply calls QPainter::drawEllipse(). So, it would take a lot of work, but you could adapt the code in QSvgTinyDocument to create a QPainterPath instead.

alitoh
15th August 2012, 14:32
Edit - Nope, QSvgRenderer does not use QPainterPath, it uses an internal data structure called "QSvgTinyDocument", which contains "QSvgNode" elements that appear to map to the same kinds of graphical elements that can be incorporated into QPainterPath. For example, the QSvgCircle::draw() method simply calls QPainter::drawEllipse(). So, it would take a lot of work, but you could adapt the code in QSvgTinyDocument to create a QPainterPath instead.

Thank you for that. I hadn't had time to check it myself, so you taking your time was really helpful.

It's a shame, really. I honestly thought it would be simpler to achieve.

QSvg is erally useful, though, and I did not know about it.