Skip to content

Fix ConsoleWidget ReplWidget.write() always scrolling to bottom (scrollToBottom not working)#3140

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
jack-mil:repl-auto-scroll
Oct 13, 2024
Merged

Fix ConsoleWidget ReplWidget.write() always scrolling to bottom (scrollToBottom not working)#3140
j9ac9k merged 1 commit intopyqtgraph:masterfrom
jack-mil:repl-auto-scroll

Conversation

@jack-mil
Copy link
Copy Markdown
Contributor

Despite having scrollToBottom='auto' in ReplWidget set to auto, the TextEdit scroll area would always scroll to the bottom, to most recently inserted text.
Desired behavior: have the scroll view stay in place if not at the bottom.
I messed around with lots of things trying to get it to work as expected. I found that moving the text cursor to the end also scrolled the view. There is no mention of this behavior in the QT docs. It does not seem to matter whether QTextEdit.moveCursor() is used, or first getting a reference, moving the cursor, and setting again using QTextEdit.setCursor() (as was being used here before. This issue was made especially hard to diagnose because the cursor is not visible.

The QTextEdit.insertPlainText() method does work as expected, and moves the cursor to the end of the inserted text. This does not scroll the view (unlike append()).

I eventually settled on just removing the line that moves the cursor to the end near the beginning of ReplWidget.write(). This fixed the issue, and I only had to change the one other place the QTextEdit has text added to use insert instead of set in order to update the cursor position to the right place upon initialization (in ConsoleWidget.__init__()).

The other changes are just pre-commit auto formatting.

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Oct 13, 2024

Thank you for the PR @jack-mil this LGTM, merging!

@j9ac9k j9ac9k merged commit c5db3a5 into pyqtgraph:master Oct 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants