How to scroll line numbers in a QTextEdit
<p>Here is my code:</p>

<pre><code>import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Editor(QPlainTextEdit):
    def __init__(self, parent):
        super(Editor, self).__init__()
        self.setPlainText( u'apple, banana\norange\nblah blah\n\nOh yeah!....\n'*2 )
        self.setParent( parent )

        self.setWordWrapMode( QTextOption.NoWrap )
        self.setViewportMargins( 50,0,0,0 )

        QObject.connect( self, SIGNAL("textChanged()"), self.repainting )

    def repainting(self) : self.parent().update()

class WinE(QMainWindow):
    def __init__(self, font=QFont( 'Monospace', 12 )):
        super(WinE, self).__init__()

        self.font = font
        self.font.setFixedPitch( True )

        self.ce = Editor( self )
        self.ce.setFont( self.font )

        self.setWindowTitle('Code Editor')

        self.textr = QRect( 3, 5, self.ce.childrenRect().x() -12, self.ce.childrenRect().height() )

        self.setGeometry( QRect(800, 840, 351, 250) )
        self.setCentralWidget( self.ce )

        self.show()

    def paintEvent(self, event):

        qp = QPainter   ()
        qp.begin        ( self )
        self.drawLiNums ( qp )
        qp.end          ()

    def drawLiNums(self, qp):

        qp.setPen       ( QColor(255, 255, 255) )
        qp.setFont      ( self.font )
        qp.drawText     ( self.textr, Qt.AlignRight, self.lineNumeration() ) 

    def lineNumeration(self):

        return ''.join( [str(n+1) +'\n' for n in range( len(self.ce.toPlainText().splitlines(False)) )] )

def main():

    app = QApplication(sys.argv)
    ex = WinE()
    sys.exit(app.exec_())

if __name__ == '__main__': main()
</code></pre>

<p><code>Editor</code> shows up with numbers, and the numbers are updating when adding new lines. But when it reaches the end of the widget, the text continues to scroll while typing, but the line numbers stop updating, and there's no scrolling whatsoever on line number area!</p>