11

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

Philip Allgaier
  • 3,505
  • 2
  • 26
  • 53
martin k
  • 111
  • 1
  • 3

2 Answers2

20
myTextEdit -> moveCursor (QTextCursor::Start) ;
myTextEdit -> ensureCursorVisible() ;
TonyK
  • 16,761
  • 4
  • 37
  • 72
18

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

QScrollBar *vScrollBar = yourTextEdit->verticalScrollBar();
vScrollBar->triggerAction(QScrollBar::SliderToMinimum);
alexisdm
  • 29,448
  • 6
  • 64
  • 99
  • This is the most general solution to the issue of scrolling. (It answered my general question about scrolling to the top of widgets.) – adam.baker Dec 03 '14 at 04:30