Kozersky
18th February 2015, 15:46
I am trying to create indentation guides for basic text viewer. Currently I have stopped at following piece of code:
def paintEvent(self, event):
font = QtGui.QFont('Courier', 10, QtGui.QFont.Light)
font_metrics = QtGui.QFontMetrics(font)
self.font_width = font_metrics.width('X')
self.font_height = font_metrics.height()
self.setFont(font)
painter = QPainter(self.viewport())
#painter.begin()
longest_line = 20
from_top = 0
painter.setPen(QtGui.QColor(0, 100, 200, 200))
for i in range(0, longest_line):
the_x = self.font_width + (i * 4 * self.font_width)
painter.drawLine(the_x, from_top, the_x, from_top + self.font_height)
QPlainTextEdit.paintEvent(self, event)
#painter.end()
#self.updateScrollbars()
super(QPlainTextEdit, self).paintEvent(event)
return
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.microsoft.com/e792686d-542b-474a-8c55-630980e72c30.
def paintEvent(self, event):
font = QtGui.QFont('Courier', 10, QtGui.QFont.Light)
font_metrics = QtGui.QFontMetrics(font)
self.font_width = font_metrics.width('X')
self.font_height = font_metrics.height()
self.setFont(font)
painter = QPainter(self.viewport())
#painter.begin()
longest_line = 20
from_top = 0
painter.setPen(QtGui.QColor(0, 100, 200, 200))
for i in range(0, longest_line):
the_x = self.font_width + (i * 4 * self.font_width)
painter.drawLine(the_x, from_top, the_x, from_top + self.font_height)
QPlainTextEdit.paintEvent(self, event)
#painter.end()
#self.updateScrollbars()
super(QPlainTextEdit, self).paintEvent(event)
return
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.microsoft.com/e792686d-542b-474a-8c55-630980e72c30.