Results 1 to 3 of 3

Thread: QPainterPath add subPath in foreground

  1. #1
    Join Date
    Mar 2015
    Posts
    3
    Thanks
    2
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default QPainterPath add subPath in foreground

    Hi,

    I use QPainterPath to draw a line. I want to add a polygon in front of the line with addPolygon to draw an arrow head.
    But the polygon is in background, and the line is always shown in front of the arrow head.

    Here my code :

    Qt Code:
    1. QPainterPath myPath;
    2. myPath.moveTo( xo,yo);
    3. myPath.lineTo( x, y );
    4. ...
    5. QPolygonF arrowHead;
    6. arrowHead << p << arrowP1 << arrowP2;
    7. myPath.addPolygon(arrowHead);
    8. myPath.closeSubpath();
    To copy to clipboard, switch view to plain text mode 

    I use QPainterPath::addEllipse too, to make disk arrow head, and I have the same problem.

    What is the solution to move subpath in foreground ?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,328
    Thanks
    317
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QPainterPath add subPath in foreground

    If you aren't specifying a brush when you draw your path, the the polygon is not being filled, and that's why the line is visible. It has nothing to do with foreground / background. All of the items in the path are at the same Z-level. If you don't want the end of the line to be visible, then calculate its endpoints correctly so it ends at the polygon border, not inside it.

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

    GuillaumeG (26th March 2015)

  4. #3
    Join Date
    Oct 2014
    Posts
    81
    Thanks
    20
    Thanked 9 Times in 9 Posts
    Qt products
    Qt5
    Platforms
    Windows
    Wiki edits
    7

    Default Re: QPainterPath add subPath in foreground

    It's possible that QPainter first fills the path with the brush and then draws all the strokes afterwards, with the pen. So the line would always be displayed on top.

    As an alternative to setting the line endpoint to the edge of the arrow, you can try using two different QPainterPaths -- then you have absolute control over the rendering order.

Similar Threads

  1. foreground problem
    By Alundra in forum Qt Programming
    Replies: 10
    Last Post: 1st April 2014, 15:23
  2. Qpainter foreground
    By hassinoss in forum Qt Programming
    Replies: 8
    Last Post: 13th March 2014, 11:32
  3. GraphicsView Foreground
    By augusbas in forum Qt Programming
    Replies: 11
    Last Post: 23rd June 2011, 12:06
  4. QPainterPath::quadTo(...) calls QPainterPath::cubicTo(...) ?
    By brucelamond in forum Qt Programming
    Replies: 0
    Last Post: 28th April 2011, 23:30
  5. How to keep window in foreground
    By szicsi in forum Qt Programming
    Replies: 5
    Last Post: 17th January 2008, 14:40

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.