I am trying to create indentation guides for basic text viewer. Currently I have stopped at following piece of code:

Qt Code:
  1. def paintEvent(self, event):
  2. font = QtGui.QFont('Courier', 10, QtGui.QFont.Light)
  3. font_metrics = QtGui.QFontMetrics(font)
  4. self.font_width = font_metrics.width('X')
  5. self.font_height = font_metrics.height()
  6. self.setFont(font)
  7.  
  8. painter = QPainter(self.viewport())
  9. #painter.begin()
  10. longest_line = 20
  11. from_top = 0
  12. painter.setPen(QtGui.QColor(0, 100, 200, 200))
  13. for i in range(0, longest_line):
  14. the_x = self.font_width + (i * 4 * self.font_width)
  15. painter.drawLine(the_x, from_top, the_x, from_top + self.font_height)
  16.  
  17. QPlainTextEdit.paintEvent(self, event)
  18. #painter.end()
  19. #self.updateScrollbars()
  20. super(QPlainTextEdit, self).paintEvent(event)
  21. return
To copy to clipboard, switch view to plain text mode 

This code is not finished as it seems to me somewhat ugly solution. My question is -- is there any guide, or piece of code I can learn from? It does not matter which language. I also could not find relevant topics in this forum, search results are too verbose.

And just to clarify, this is what I am trying to reproduce: https://visualstudiogallery.msdn.mic...5-630980e72c30.