3

I have a simple QtextEdit form which i am using as a sort of log. Events are written down into the form, so user can review history events. I am using textEdit.append() to add new lines to the form. However textEdit.append() , append the text on bottom of the buffer, so the newest events are shown on the bottom, Is there any reasonable way to append on top, so newest events are shown on the top ?

Thanks.

101
  • 8,514
  • 6
  • 43
  • 69
Dulus
  • 33
  • 1
  • 4

1 Answers1

4

You can use the insertPlainText method to insert text anywhere in the current text. Place a cursor to specify where the text is to be inserted. In your case you'd place it at the start:

from PyQt5.QtGui import QTextCursor

# set the cursor position to 0
cursor = QTextCursor(textEdit.document())
# set the cursor position (defaults to 0 so this is redundant)
cursor.setPosition(0)
textEdit.setTextCursor(cursor)

# insert text at the cursor
textEdit.insertPlainText('your text here')
101
  • 8,514
  • 6
  • 43
  • 69