Results 1 to 9 of 9

Thread: How to get points drawn by strokePath from outline of QPainterPath

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get points drawn by strokePath from outline of QPainterPath

    Quote Originally Posted by userman View Post
    This is (3 steps - tricky) way, but gives you 100% accuracy of points drawn by QPainter.
    To be honest I didn't get the point of this all - QPainterPath has a public API for reading all coordinates ?

    Qt Code:
    1. QPainterPath polygonPath;
    2. polygonPath.moveTo(10.0, 80.0);
    3. ...
    4.  
    5. for ( int i = 0; i < polygonPath.elementCount(); i++ )
    6. {
    7. const auto el = polygonPath.elementAt( i );
    8. switch( el.type() )
    9. {
    10. case QPainterPath::MoveToElement:
    11. ....
    12. break;
    13. ....
    14. };
    15. }
    To copy to clipboard, switch view to plain text mode 
    In case you really need a record/replay paint device using QPicture would make more sense as no file IO would be involved. Of course you could also write your own type of paint device for recording QPainter commands like being done f.e in http://qwt.sourceforge.net/class_qwt...nt_device.html.

    Uwe

  2. #2
    Join Date
    Apr 2017
    Posts
    5
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: How to get points drawn by strokePath from outline of QPainterPath

    Quote Originally Posted by Uwe View Post
    To be honest I didn't get the point of this all - QPainterPath has a public API for reading all coordinates ?

    Qt Code:
    1. QPainterPath polygonPath;
    2. polygonPath.moveTo(10.0, 80.0);
    3. ...
    4.  
    5. for ( int i = 0; i < polygonPath.elementCount(); i++ )
    6. {
    7. const auto el = polygonPath.elementAt( i );
    8. switch( el.type() )
    9. {
    10. case QPainterPath::MoveToElement:
    11. ....
    12. break;
    13. ....
    14. };
    15. }
    To copy to clipboard, switch view to plain text mode 
    In case you really need a record/replay paint device using QPicture would make more sense as no file IO would be involved. Of course you could also write your own type of paint device for recording QPainter commands like being done f.e in http://qwt.sourceforge.net/class_qwt...nt_device.html.

    Uwe
    Uwe, you didn't get the point of this all... because you did not read my first post carefully. Please view attached image in first post.
    qt-quest1.jpg
    Yes you can read those points this way
    Qt Code:
    1. polygonPath.elementAt( i );
    To copy to clipboard, switch view to plain text mode 
    But it gives you only the middle points of the QPen, marked as green/yellow dash line on my attached image.
    In my example i need to find points marked as black line (on attached image)
    If you known solution how to do this, please share this info.

    Thanks d_stranz yes I can use QIODevice like this:

    Qt Code:
    1. QBuffer buffer;
    2. buffer.open(QBuffer::ReadWrite);
    3. QSvgGenerator generator;
    4. generator.setOutputDevice(&buffer);
    5. ...
    6. buffer.seek(0);
    7. QString s(buffer.readAll());
    8. qInfo() << s;
    To copy to clipboard, switch view to plain text mode 
    (do not create physical file - but i did not it for illustrate what is going on. For my purpose, I needed those points in XML anyway, but use setOutputDevice for speed up process is a very good idea)

    In example form attached image - has to be created stroke path from red Curve, and read stroke path coordinates from SVG to find those points of black path.
    Or there is better solution Uwe?

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get points drawn by strokePath from outline of QPainterPath

    Quote Originally Posted by userman View Post
    Uwe, you didn't get the point of this all... because you did not read my first post carefully.
    Well, there is QPainterPathStroker that is also internally used to create the QPainterPath that gets finally rendered.
    So what you need to do is to set up the stroker with the attributes of your pen and then the strokedPath can be read like in my previous posting.

    Thought you were talking about the strokedPath in your initial posting as you called it like that.

    Uwe

  4. The following user says thank you to Uwe for this useful post:

    userman (7th February 2018)

  5. #4
    Join Date
    Apr 2017
    Posts
    5
    Thanks
    2
    Thanked 1 Time in 1 Post

    Default Re: How to get points drawn by strokePath from outline of QPainterPath

    So the (other) final solution is:

    Draw along outline points of shape:
    qt-quest1.1.jpg

    Qt Code:
    1. QPainterPath path(QPointF(80, 320));
    2. path.lineTo(QPointF(240,90));
    3. path.lineTo(QPointF(330,240));
    4. path.lineTo(QPointF(620,180));
    5. path.lineTo(QPointF(730,110));
    6.  
    7. stroker.setCapStyle(Qt::RoundCap);
    8. stroker.setJoinStyle(Qt::RoundJoin);
    9. stroker.setWidth(100);
    10.  
    11. QPainterPath strokePath = stroker.createStroke(path).simplified();
    12.  
    13. for (int i = 0; i < strokePath.elementCount()-1; i++)
    14. {
    15. QPainterPath::Element p1 = strokePath.elementAt(i);
    16. QPainterPath::Element p2 = strokePath.elementAt(i+1);
    17. painter->setPen(QPen(i % 2 == 0 ? Qt::red : Qt::green, 1));
    18. painter->drawLine(QPointF(p1.x, p1.y), QPointF(p2.x, p2.y));
    19. }
    To copy to clipboard, switch view to plain text mode 

    Solved.

Similar Threads

  1. Adjusting QLineF points AFTER it has been drawn
    By bauervision in forum Qt Programming
    Replies: 0
    Last Post: 8th March 2017, 13:46
  2. How to draw strokepath
    By rajji_saini in forum Newbie
    Replies: 2
    Last Post: 5th April 2011, 01:11
  3. Remove unused points from a QPainterPath
    By JaV0 in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2010, 08:35
  4. Remove points from a QPainterPath
    By JaV0 in forum Qt Programming
    Replies: 0
    Last Post: 3rd March 2010, 16:27
  5. Checking for intersect of QPainterPath OUTLINE?
    By SonOfGuest in forum Qt Programming
    Replies: 1
    Last Post: 12th May 2009, 00:30

Tags for this Thread

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.