How to scroll QPlainTextEdit to top?

2020-07-06 05:13发布

问题:

I would like to automatically scroll to the top in a QPlainTextEdit widget after put in some text. How can I realize that?

回答1:

myTextEdit -> moveCursor (QTextCursor::Start) ;
myTextEdit -> ensureCursorVisible() ;


回答2:

As QTextEdit inherits from QAbstractScrollArea, you can move its scrollbars:

QScrollBar *vScrollBar = yourTextEdit->verticalScrollBar();
vScrollBar->triggerAction(QScrollBar::SliderToMinimum);