I’m hoping someone might shed some light as to why I’m having a problem with QPainterPath::arcTo() used to draw the inner pie boundary in the image below.
The inner and outer arcs have the same start angle and sweep length, but they don't render that way. Why?
pieIssue.jpg

The pie shapes are drawn with:
QPainterPath::arcTo(const QRectF & rectangle, qreal startAngle, qreal sweepLength)

The method is giving unexpected results with the startAngle and sweepLength.

Looking at the image, I expect the inner arc to begin (and end) coincident with the outer arc, but it doesn’t. The center, startAngle, and sweepLength are the same for both.

Note, I computed the desired arc start/end point (shown in the red circle as a yellow square).

Qt Code:
  1. void GraphicsPieFramed::createPaths()
  2. {
  3. // Clear the paths.
  4. mOutlinePath = QPainterPath();
  5. mFacePath = QPainterPath();
  6.  
  7. mMaxelSize = SCENE_SCALE*maxelDiameter(printHeadDiameter(), mVoltage);
  8.  
  9. double span = -normAngle360(mAngleEnd-mAngleBegin);
  10.  
  11. mOutlinePath.addRect(-0.5*mSize.width(), -0.5*mSize.height(), mSize.width(), mSize.height());
  12.  
  13. // outer pie
  14. QPainterPath outerPie;
  15. outerPie.moveTo(QPointF(0.0, 0.0));
  16. outerPie.arcTo(QRectF(-0.5*mSize.width(), -0.5*mSize.height(), mSize.width(), mSize.height()),
  17. -mAngleBegin, span);
  18. outerPie.closeSubpath();
  19. mFacePath.addPath(outerPie);
  20.  
  21. // inner pie
  22. QPainterPath innerPie;
  23. innerPie.moveTo(QPointF(0.0, 0.0));
  24. innerPie.arcTo(QRectF(-0.5*mSize.width()+mFrameWidth, -0.5*mSize.height()+mFrameHeight,
  25. mSize.width()-2.0*mFrameWidth, mSize.height()-2.0*mFrameHeight),
  26. -mAngleBegin, span);
  27. innerPie.closeSubpath();
  28. mFacePath.addPath(innerPie);
  29.  
  30. if(mFrameEnabled && mFrameWidth < 0.5*mSize.width() && mFrameHeight < 0.5*mSize.height())
  31. {
  32. mFacePath.addPath(innerPie);
  33. }
  34.  
  35. mFacePath.addEllipse(QPointF(0.0, 0.0), 3.0, 3.0); // Center location
  36.  
  37. createMaxelPaths();
  38. createResizeHandlePaths();
  39. createRotateHandlePath();
  40. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. void GraphicsPieFramed::createResizeHandlePaths()
  2. {
  3. // Clear the paths.
  4. mResizeLeftPath = QPainterPath();
  5. mResizeRightPath = QPainterPath();
  6. mResizeBottomPath = QPainterPath();
  7. mResizeTopPath = QPainterPath();
  8. mResizeBottomLeftPath = QPainterPath();
  9. mResizeBottomRightPath = QPainterPath();
  10. mResizeTopLeftPath = QPainterPath();
  11. mResizeTopRightPath = QPainterPath();
  12. mResizeAngleBeginPath = QPainterPath();
  13. mResizeAngleEndPath = QPainterPath();
  14. mResizeFrameWidthPath = QPainterPath();
  15. mResizeFrameHeightPath = QPainterPath();
  16.  
  17. double const sizeHandleHalf(0.5*SIZE_HANDLE);
  18. double const sizeHandleHalfDiag(sizeHandleHalf*sqrt(2.0));
  19. double const left(-0.5*mSize.width());
  20. double const right(0.5*mSize.width());
  21. double const bottom(-0.5*mSize.height());
  22. double const top(0.5*mSize.height());
  23.  
  24. // left
  25. mResizeLeftPath.addRect(left-sizeHandleHalf, -sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  26. // right
  27. mResizeRightPath.addRect(right-sizeHandleHalf, -sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  28. // bottom
  29. mResizeBottomPath.addRect(-sizeHandleHalf, bottom-sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  30. // top
  31. mResizeTopPath.addRect(-sizeHandleHalf, top-sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  32.  
  33. // bottom-left
  34. mResizeBottomLeftPath.addRect(left-sizeHandleHalf, bottom-sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  35. // bottom-right
  36. mResizeBottomRightPath.addRect(right-sizeHandleHalf, bottom-sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  37. // top-left
  38. mResizeTopLeftPath.addRect(left-sizeHandleHalf, top-sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  39. // top-right
  40. mResizeTopRightPath.addRect(right-sizeHandleHalf, top-sizeHandleHalf, SIZE_HANDLE, SIZE_HANDLE);
  41.  
  42. // begin angle
  43. double xBegin = 0.5*mSize.width()*cos(DEG2RAD*mAngleBegin);
  44. double yBegin = 0.5*mSize.height()*sin(DEG2RAD*mAngleBegin);
  45. mResizeAngleBeginPath.addEllipse(xBegin-sizeHandleHalfDiag, yBegin-sizeHandleHalfDiag,
  46. 2.0*sizeHandleHalfDiag, 2.0*sizeHandleHalfDiag);
  47. // begin angle inner frame
  48. double lenBegin = sqrt(xBegin*xBegin + yBegin*yBegin);
  49. double xBeginPart = mFrameWidth*cos(DEG2RAD*mAngleBegin);
  50. double yBeginPart = mFrameHeight*sin(DEG2RAD*mAngleBegin);
  51. double lenBeginPart = sqrt(xBeginPart*xBeginPart + yBeginPart*yBeginPart);
  52. double x2Begin = interp(xBegin, 0.0, lenBeginPart/lenBegin);
  53. double y2Begin = interp(yBegin, 0.0, lenBeginPart/lenBegin);
  54. mResizeAngleBeginPath.addRect(x2Begin-sizeHandleHalf, y2Begin-sizeHandleHalf, 2.0*sizeHandleHalf, 2.0*sizeHandleHalf);
  55.  
  56. // end angle
  57. double xEnd = 0.5*mSize.width()*cos(DEG2RAD*mAngleEnd);
  58. double yEnd = 0.5*mSize.height()*sin(DEG2RAD*mAngleEnd);
  59. mResizeAngleEndPath.addEllipse(xEnd-sizeHandleHalfDiag, yEnd-sizeHandleHalfDiag,
  60. 2.0*sizeHandleHalfDiag, 2.0*sizeHandleHalfDiag);
  61. // end angle inner frame
  62. double lenEnd = sqrt(xEnd*xEnd + yEnd*yEnd);
  63. double xEndPart = mFrameWidth*cos(DEG2RAD*mAngleEnd);
  64. double yEndPart = mFrameHeight*sin(DEG2RAD*mAngleEnd);
  65. double lenEndPart = sqrt(xEndPart*xEndPart + yEndPart*yEndPart);
  66. double x2End = interp(xEnd, 0.0, lenEndPart/lenEnd);
  67. double y2End = interp(yEnd, 0.0, lenEndPart/lenEnd);
  68. mResizeAngleEndPath.addRect(x2End-sizeHandleHalf, y2End-sizeHandleHalf, 2.0*sizeHandleHalf, 2.0*sizeHandleHalf);
  69.  
  70. // frame width
  71. mResizeFrameWidthPath.addEllipse(left-sizeHandleHalfDiag+mFrameWidth, top-sizeHandleHalfDiag,
  72. 2.0*sizeHandleHalfDiag, 2.0*sizeHandleHalfDiag);
  73.  
  74. // frame height
  75. mResizeFrameHeightPath.addEllipse(left-sizeHandleHalfDiag, top-sizeHandleHalfDiag-mFrameHeight,
  76. 2.0*sizeHandleHalfDiag, 2.0*sizeHandleHalfDiag);
  77. }
To copy to clipboard, switch view to plain text mode 

Thanks!