Results 1 to 3 of 3

Thread: Vector graphic to QPainterPath

  1. #1
    Join Date
    Mar 2011
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default Vector graphic to QPainterPath

    This is a doubt I got from checking the Vector Deformation Demo. 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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,348
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Vector graphic to QPainterPath

    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.
    Last edited by d_stranz; 10th August 2012 at 16:41.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    alitoh (15th August 2012)

  4. #3
    Join Date
    Mar 2011
    Posts
    82
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanks
    13
    Thanked 2 Times in 2 Posts

    Default Re: Vector graphic to QPainterPath

    Quote Originally Posted by d_stranz View Post
    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.

Similar Threads

  1. Copying vector of pointers to another vector
    By Momergil in forum Newbie
    Replies: 12
    Last Post: 24th September 2011, 22:09
  2. QPainterPath::quadTo(...) calls QPainterPath::cubicTo(...) ?
    By brucelamond in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2011, 23:30
  3. QGraphicItem with vector graphic
    By jobrandt in forum Qt Programming
    Replies: 3
    Last Post: 3rd September 2007, 14:52
  4. insert in a vector of vector
    By mickey in forum General Programming
    Replies: 3
    Last Post: 6th March 2007, 08:45
  5. vector of vector size
    By mickey in forum General Programming
    Replies: 5
    Last Post: 13th February 2007, 15:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.