Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-120044

QTextCharFormat applied to a QTextCursor influences new document

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.3
    • GUI: Text handling
    • None
    • macOS 14.1.2, Intel
    • All

    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");

       

       
       

      Attachments

        1. 2023-12-12_16-15-19.png
          2023-12-12_16-15-19.png
          116 kB
        2. CMakeLists.txt
          0.3 kB
        3. main.cpp
          1.0 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            andreas.loew andreas.loew
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes