pythonscrollpyqtqtexteditqscrollarea

Scrolling in QScrollArea pyqt


How can I auto scroll for the scroll area? For example, when there is a new update instead of the view of the scroll area staying the same, I want to go down with the new text. Think of it as in a CMD console, when you type a command it autoscroll with the output.


Solution

  • Use QTextEdit.moveCursor to set the location you want to scroll to, and then use QTextEdit.ensureCursorVisible to scroll to it:

    textedit.moveCursor(QtGui.QTextCursor.End)
    textedit.ensureCursorVisible()