문제

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top