I am trying to build a arc with some text. I am able to create the arc and I can place the text along with curve. But so far I cant find a way ro rotate text perpendicular to the curve.
Here is the code I am trying

Qt Code:
  1. from __future__ import division
  2. import os
  3. import sys
  4. from PyQt4 import QtGui,QtCore
  5. import math
  6.  
  7. class PathPaintTest(QtGui.QFrame):
  8.  
  9.  
  10. def __init__(self, *args):
  11. super (PathPaintTest, self).__init__(*args)
  12. self.setMaximumSize(250, 110)
  13. self.setMinimumSize(250, 110)
  14. self.setFrameShape(QtGui.QFrame.WinPanel)
  15. self.setFrameShadow(QtGui.QFrame.Sunken)
  16.  
  17. def paintEvent(self, event):
  18. hw = QtCore.QString("Hello World")
  19. drawWidth = self.width() / 100
  20. painter = QtGui.QPainter(self)
  21. pen = painter.pen()
  22. pen.setWidth(drawWidth)
  23. pen.setColor(QtGui.QColor(QtCore.Qt.red))
  24. painter.setPen(pen)
  25. painter.translate(5,0)
  26. cc1 = QtCore.QPointF(5, -15)
  27. cc2 = QtCore.QPointF(220, -15)
  28. path1 = QtGui.QPainterPath(QtCore.QPointF(5, 140))
  29. path1.cubicTo(cc1, cc2, QtCore.QPointF(240, 140))
  30. painter.drawPath(path1)
  31.  
  32. pen.setColor(QtGui.QColor(QtCore.Qt.yellow))
  33. painter.setPen(pen)
  34. font = painter.font()
  35. font.setPixelSize(drawWidth * 5)
  36. painter.setFont(font)
  37. percentIncrease = 1 / (hw.size() + 1)
  38. perecent = 0
  39. for i in range(hw.size()):
  40. perecent+=percentIncrease
  41. point = QtCore.QPointF(path1.pointAtPercent(perecent))
  42. painter.drawText(point,QtCore.QString(hw[i]))
  43.  
  44. QtGui.QFrame.paintEvent(self,event)
  45.  
  46.  
  47. class TextTest(QtGui.QWidget):
  48. def __init__(self):
  49. super(TextTest, self).__init__()
  50. self.initUI()
  51.  
  52. def keyPressEvent(self, event):
  53. if event.key() == QtCore.Qt.Key_Escape:
  54. self.close()
  55.  
  56. def initUI(self):
  57. self.mypb = PathPaintTest()
  58. hbox = QtGui.QHBoxLayout()
  59. hbox.addWidget(self.mypb)
  60.  
  61. vbox = QtGui.QVBoxLayout()
  62. vbox.addLayout(hbox)
  63.  
  64. self.setLayout(vbox)
  65. self.setGeometry(1900, 500, 450, 180)
  66. self.setWindowTitle('Text Test')
  67.  
  68. def run():
  69.  
  70. app = QtGui.QApplication(sys.argv)
  71. ex = TextTest()
  72. ex.show()
  73. sys.exit(app.exec_())
  74.  
  75. if __name__ == "__main__":
  76. run()
To copy to clipboard, switch view to plain text mode 
But I am trying to achieve something close to this post http://zrusin.blogspot.com/2006/11/text-on-path.html . Like text want to be rotated based on the angle. Any idea how I can do with QPainterPath and QPainter or any other methods ?

I am looking a output like this

output.jpg

Please let me know which will be the best way to achieve this .

Thanks in advance