I am trying to paint some lines in a QTextEdit
but when paintEvent
it is called the whole QTextEdit
text clears, the lines are drawn, no further text input possible. If I scroll, the drawn lines act very weird, somehow multiply on horizontal or vertical. I want to paint on the QTextEdit
w/o affecting it's text and the painted stuff to act normal when scrolling, to keep its coordinates.
Here is the code:
class TextEdit(QTextEdit):
def __init__(self, parent = None):
super(TextEdit, self).__init__(parent)
self.setViewportMargins(10, 0, 0, 0)
def paintEvent(self, event):
painter = QPainter(self.viewport())
painter.drawLine(10, 10, 200, 10)
Add this to the bottom of your paintEvent
method:
super(TextEdit, self).paintEvent(event)