Results 1 to 4 of 4

Thread: How to use QPainterPathStroker?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to use QPainterPathStroker?

    Hi,

    I need to create an outline following a curve with a fixed width (said 100), as shown in my attachment 1.

    To do this, I use QPainterPathStroker using following code. However, the resulting stroker joins them with the curve (see attachment 2). What I want is the outline without joining with the curve. How can I do so? Thanks!

    Qt Code:
    1. QVector<QPointF> myCurve; // <-- myCurve is calculated somewhere else.
    2.  
    3. QPainterPath curvePath;
    4. curvePath.moveTo( myCurve[ 0 ] );
    5. for ( int idx = 1; idx < myCurve.size(); idx++ ) {
    6. curvePath.lineTo( myCurve[ idx ] );
    7. }
    8.  
    9. stroker.setCapStyle( Qt::RoundCap );
    10. stroker.setJoinStyle( Qt::RoundJoin );
    11. stroker.setWidth( 100 );
    12. QPainterPath outline = stroker.createStroke ( curvePath );
    13. painter->drawPath( outline );
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images
    • File Type: png 1.png (3.0 KB, 77 views)
    • File Type: png 2.png (7.1 KB, 75 views)

  2. #2
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to use QPainterPathStroker?

    Anyone please?

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How to use QPainterPathStroker?

    Do you set a fill brush for your painter before drawing the path? Do you set the pen to "NoPen"?

  4. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to use QPainterPathStroker?

    Quote Originally Posted by d_stranz View Post
    Do you set a fill brush for your painter before drawing the path? Do you set the pen to "NoPen"?
    The problem is not pen or brush, it is problem that it connects the stroking path with the input curve path, causing error in my other computation. What I need is the outline without connecting to the center red curve.

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.