Actually, the original C++ code has the same problem. You get a better result if you make the angle negative at line 44 of your Python version.

The solution can e simplified a little by getting Qt to do more of the mathematics:
Qt Code:
  1. #include <QtGui>
  2. #include <cmath>
  3.  
  4. class Widget : public QWidget
  5. {
  6. public:
  7. Widget ()
  8. : QWidget() { }
  9. private:
  10. void paintEvent ( QPaintEvent *)
  11. {
  12. QString hw("hello world");
  13. int drawWidth = width() / 100;
  14. QPainter painter(this);
  15. QPen pen = painter.pen();
  16. pen.setWidth(drawWidth);
  17. pen.setColor(Qt::darkGreen);
  18. painter.setPen(pen);
  19.  
  20. QPainterPath path(QPointF(0.0, 0.0));
  21.  
  22. QPointF c1(width()*0.2,height()*0.8);
  23. QPointF c2(width()*0.8,height()*0.2);
  24.  
  25. path.cubicTo(c1,c2,QPointF(width(),height()));
  26.  
  27. //draw the bezier curve
  28. painter.drawPath(path);
  29.  
  30. //Make the painter ready to draw chars
  31. QFont font = painter.font();
  32. font.setPixelSize(drawWidth*2);
  33. painter.setFont(font);
  34. pen.setColor(Qt::red);
  35. painter.setPen(pen);
  36.  
  37. qreal percentIncrease = (qreal) 1/(hw.size()+1);
  38. qreal percent = 0;
  39.  
  40. for ( int i = 0; i < hw.size(); i++ ) {
  41. percent += percentIncrease;
  42.  
  43. QPointF point = path.pointAtPercent(percent);
  44. qreal angle = path.angleAtPercent(percent); // Clockwise is negative
  45.  
  46. painter.save();
  47. // Move the virtual origin to the point on the curve
  48. painter.translate(point);
  49. // Rotate to match the angle of the curve
  50. // Clockwise is positive so we negate the angle from above
  51. painter.rotate(-angle);
  52. // Draw a line width above the origin to move the text above the line
  53. // and let Qt do the transformations
  54. painter.drawText(QPoint(0, -pen.width()),QString(hw[i]));
  55. painter.restore();
  56. }
  57. }
  58.  
  59. };
  60.  
  61. int main(int argc, char **argv)
  62. {
  63. QApplication app(argc, argv);
  64. Widget widget;
  65. widget.show();
  66. return app.exec();
  67. }
To copy to clipboard, switch view to plain text mode