Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Auto scrolling text view (TextEdit) to the bottom when new text is appended
tumbledry last edited by
With pyQt5 and QML I'm trying to implement a continuously scrolling text view. As new messages arrive, I wish to append them to the text view and have the view automatically scroll down to display the new message. This would appear similar to common chat applications such as IRC or Slack.
I've tried simply using a QTextEdit defined in QML, and using a property for the TextEdit's
text field. I keep adding more characters to the text property string, which are displayed until the TextEdit's view rectangle is full -- but when the text exceeds the viewable area, scroll bars do not appear and the view does not scroll down. This surprised me because the QTextEdit docs state, "QTextEdit can display images, lists and tables. If the text is too large to view within the text edit's viewport, scroll bars will appear"
I've tried something similar with TextArea but didn't make much progress with that either.
- What's the right way to implement an autoscrolling text view with QML and Qt5?
- Do I need to manipulate any properties of the TextEdit other than
textwhen appending new messages to the view, in order to get the view to automatically scroll down to show the latest messages? If so, can this be done in QML?
In researching this problem I've come across multiple solutions that applied to earlier versions of Qt , but don't appear to work on Qt5.
Thanks for any assistance!
A Former User last edited by
Hi! Widgets and QtQuick items are not the same. QTextEdit is not the same as the QML type TextEdit. The documentation page for TextEdit can be found her: TextEdit QML Type. There it says:
Note that the TextEdit does not implement scrolling, following the cursor, or other behaviors specific to a look-and-feel.
But the doc page has an example for how to add scrolling / cursor following.