Results 1 to 2 of 2

Thread: How to render part of a QPainterPath?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to render part of a QPainterPath?

    Hello everybody,

    I'm trying to render animations in which a complex QPainterPath (essentially made of curves) is drawn step-by-step on the screen. One can think of it as a "manual handwriting" effect.

    In order to perform that effect correctly, I'd need to be able to draw only part of the path. However, I cannot find any method in the API or combination of methods that would allow me to do that. Would someone have a suggestion on that topic?

  2. #2
    Join Date
    Jul 2008
    Posts
    24
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to render part of a QPainterPath?

    Just for the record, I have been able to solve this problem using a dash pattern. Following is an example code, where dLength is the amount of the painterPath we want to draw:

    Qt Code:
    1. QPen painterPen(painter->pen());
    2. QPen pen(painterPen);
    3. QVector<qreal> dashes;
    4. // The first element of the vector is the length we want to draw
    5. // We must divide it by the width of the pen because
    6. // the dash painting works with pen units.
    7. // The second element is the empty part of the path - setting it
    8. // to the length of the path ensures the dash pattern won't repeat.
    9. dashes << dLength / pen.width() << painterPath.length();
    10. pen.setDashPattern(dashes);
    11. painter->setPen(pen);
    12. painter->drawPath(painterPath);
    13. painter->setPen(painterPen);
    To copy to clipboard, switch view to plain text mode 

    It works good and fast. And of course, it is possible to draw from the middle of the path by using 4 values in the vector instead of 2.

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

    Mechan (31st December 2012)

Similar Threads

  1. Qpen, QBrush or QPainterpath problem
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 14th July 2009, 11:53
  2. Render from a thread into a pixmap?
    By rage in forum Qt Programming
    Replies: 12
    Last Post: 11th May 2009, 10:14
  3. Part Folder Problem
    By sujan.dasmahapatra in forum Qt Programming
    Replies: 1
    Last Post: 19th February 2009, 12:53
  4. Client/Server Error: BadIDChoice
    By 3nc31 in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 10:22
  5. QPainterPath drawing problem
    By shad in forum Qt Programming
    Replies: 3
    Last Post: 17th January 2007, 13:30

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.