Details
-
Bug
-
Resolution: Unresolved
-
P3: Somewhat important
-
None
-
5.14.2
-
None
Description
I created a subclass of QTextEdit, overrided keyPressEvent and enclosed everything inside beginEditBlock/endEditBlock cursor commands (I want to do some custom stuff, and I don't want this stuff to clutter undo history).
class CustomTextEdit : public QTextEdit { public: using QTextEdit::QTextEdit; void keyPressEvent(QKeyEvent *e) override } textCursor().beginEditBlock(); // Do some custom stuff QTextEdit::keyPressEvent(e); textCursor().endEditBlock(); } };
Then I add some large text so that it does not fit to the view and scrollbar appears. After that I move cursor to the very end of the document, and press Enter to create a new line - scroll immediately jumps to the very beginning of the document. When I start typing, the scroll returns to the cursor.
The same happens if I try setting cursor right after I inserted a block (inside a beginEditBlock/endEditBlock; here "edit" is a QTextEdit):
auto cursor = edit->textCursor();
cursor.beginEditBlock();
cursor.insertBlock();
edit->setTextCursor(cursor);
cursor.endEditBlock();
I've attached minimal working example demonstrating this issue.
There is also a workaround: I can call "ensureCursorVisible" after "textCursor().endEditBlock()" (in the first code snippet), and it works fine. For the second snippet, it's sufficient to swap two lines.