Results 1 to 5 of 5

Thread: QGraphicsView / QPainter / QGraphicsItem arc drawing bug.

  1. #1
    Join Date
    Dec 2015
    Posts
    12
    Qt products
    PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView / QPainter / QGraphicsItem arc drawing bug.

    Hi.

    I have arc:

    A coordinates (arc start point):
    X: 31.963
    Y: 70.548

    B coordinates (arc end point):
    X: 26.963
    Y: 65.548

    C coordinates (arc center point):
    X: 31.963
    Y: 65.548

    calculated:
    radius = 5.0
    startAngle = 90.0
    endAngle = 180.0
    spanAngle = 90.0

    Using calculated data, the arc must be placed between 9 and 12 o'clock:

    arc1.png

    But its placed between 6 and 9 o'clock:

    arc2.png

    Why? QPainter / QGraphicsView bug? Or what?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView / QPainter / QGraphicsItem arc drawing bug.

    Are you sure it is a bug?

    Angle 0 could be at the horizontal axis pointing right, then 90° would be down if the angle is applied clockwise and 180° would be to the left.

    Cheers,
    _

  3. #3
    Join Date
    Dec 2015
    Posts
    12
    Qt products
    PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView / QPainter / QGraphicsItem arc drawing bug.

    Yes, i think a bug found.
    I'm calculating angles using:
    startangle = (atan2(a.y() - c.y(), a.x() - c.x())*180 / pi)*16
    endangle = (atan2(b.y() - c.y(), b.x() - c.x())*180 / pi)*16
    spanangle = endangle - startangle

    Sometimes angles is + or -. Maybe problem in this?
    I can povide coordinates, and you can try to draw using it.
    Last edited by kloopa; 15th January 2016 at 14:21.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    315
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QGraphicsView / QPainter / QGraphicsItem arc drawing bug.

    Maybe you are having trouble with QPainter's device coordinate system. 0, 0 is at the top left, and the device coordinates increase as you go right and down. So everything is upside-down with respect to world coordinates.

  5. #5
    Join Date
    Dec 2015
    Posts
    12
    Qt products
    PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView / QPainter / QGraphicsItem arc drawing bug.

    My settings (python3):

    Qt Code:
    1. graphicsView.scene.setSceneRect(0, 1000, 1000, -1000)
    2. graphicsView.setRenderHints(QPainter.Antialiasing)
    3. graphicsView.scale(2.5, -2.5)
    To copy to clipboard, switch view to plain text mode 

    It sets X0.0, Y0.0 to lower left corner.

    Arcs:
    Qt Code:
    1. arcs = [
    2. {'a': QPointF(31.963, 60.548), 'b': QPointF(31.963, 70.548), 'c': QPointF(31.963, 65.548), 'direction': 1},
    3. {'a': QPointF(24.254, 70.548), 'b': QPointF(24.254, 114.148), 'c': QPointF(24.254, 92.348), 'direction': -1},
    4. {'a': QPointF(24.254, 106.548), 'b': QPointF(24.254, 78.148), 'c': QPointF(24.254, 92.348), 'direction': 1},
    5. {'a': QPointF(35.254, 78.148), 'b': QPointF(35.254, 106.548), 'c': QPointF(35.254, 92.348), 'direction': 1},
    6. {'a': QPointF(35.254, 114.148), 'b': QPointF(35.254, 70.548), 'c': QPointF(35.254, 92.348), 'direction': -1},
    7. {'a': QPointF(31.963, 70.548), 'b': QPointF(26.963, 65.548), 'c': QPointF(31.963, 65.548), 'direction': 1}
    8. ]
    To copy to clipboard, switch view to plain text mode 

    a - arc start point
    b - arc end point
    c - arc center point
    direction - (1 - counter-clockwise) and (-1 - clockwise)

    If you don't understand python:

    Qt Code:
    1. 1st Arc (counter-clockwise)
    2. start_point: X31.963 Y60.548
    3. end_point: X31.963 Y70.548
    4. center: X31.963 Y65.548
    5. ------------------------------
    6. ------------------------------
    7. 2nd Arc (clockwise)
    8. start_point: X24.254 Y70.548
    9. end_point: X24.254 Y114.148
    10. center: X24.254 Y92.348
    11. ------------------------------
    12. ------------------------------
    13. 3rd Arc (counter-clockwise)
    14. start_point: X24.254 Y106.548
    15. end_point: X24.254 Y78.148
    16. center: X24.254 Y92.348
    17. ------------------------------
    18. ------------------------------
    19. 4th Arc (counter-clockwise)
    20. start_point: X35.254 Y78.148
    21. end_point: X35.254 Y106.548
    22. center: X35.254 Y92.348
    23. ------------------------------
    24. ------------------------------
    25. 5th Arc (clockwise)
    26. start_point: X35.254 Y114.148
    27. end_point: X35.254 Y70.548
    28. center: X35.254 Y92.348
    29. ------------------------------
    30. ------------------------------
    31. 6th Arc (counter-clockwise)
    32. start_point: X31.963 Y70.548
    33. end_point: X26.963 Y65.548
    34. center: X31.963 Y65.548
    To copy to clipboard, switch view to plain text mode 

    calculating arc angles:
    Qt Code:
    1. startangle = (atan2(a.y() - c.y(), a.x() - c.x())*180 / pi)*16
    2. endangle = (atan2(b.y() - c.y(), b.x() - c.x())*180 / pi)*16
    3. spanangle = endangle - startangle
    To copy to clipboard, switch view to plain text mode 
    Try to draw this 6 arcs.

    Correct drawing looks like:

    arcs.png

    Green dot - arc start point
    Red dot - arc end point
    Last edited by kloopa; 16th January 2016 at 09:11.

Similar Threads

  1. Drawing with QPainter in a QGLWidget
    By jshafferman in forum Qt Programming
    Replies: 1
    Last Post: 2nd May 2014, 20:09
  2. drawing lines using qpainter from file
    By neutrino in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2013, 09:03
  3. Drawing on QGraphicsItem.
    By ommharidaas in forum Qt Programming
    Replies: 9
    Last Post: 21st September 2011, 13:40
  4. Text drawing with QPainter
    By Rambobino in forum Qt Programming
    Replies: 2
    Last Post: 1st November 2010, 17:26
  5. Drawing a QPixmap transparently with QPainter
    By ComServant in forum Newbie
    Replies: 2
    Last Post: 11th October 2010, 23:10

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.