Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.5.3
-
None
-
macOS 14.1.2, Intel
Description
I've created a QPlainTextEdit and use QTextCursor to highlight parts of the text.
When highlighting a " " (whitespace) character at the start of a line, setting a new text suddenly is all highlighted.
I am using a QTextCursor to find the line to highlight, and a 2nd QTextCursor to highlight the characters. In my original code, searching for some text to underline inside the block.
Highlighting the code works without any issue. But when a new text ist set, the whole text is now underlined.
This only happens, when the first character in the block is highlighted. Highlighting any other does not trigger the issue.
Also only using the highlightCursor alone does not trigger it...
Excerpt from the code, complete project included:
plainTextEdit.setPlainText("hello\n world\n!");
QTextCursor cursor = plainTextEdit.textCursor();
cursor.setPosition(plainTextEdit.document()->findBlockByNumber(1).position());
plainTextEdit.setTextCursor(cursor);
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
QTextCursor highlightCursor(plainTextEdit.document());
highlightCursor.setPosition(6, QTextCursor::MoveAnchor); // setting it to 7 & 8 works
highlightCursor.setPosition(7, QTextCursor::KeepAnchor);
highlightCursor.setCharFormat(underlined);
plainTextEdit.clear();
plainTextEdit.setPlainText("this should not be underlined");