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

QTextEdit resets formatting after empty line

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.3.2, 6.6.1
    • None
    • Windows 10 and 11 (mingw), Linux/X11 (gcc)

    Description

      A paragraph/text block has formatting (QTextCharFormat or QTextBlockFormat). When a new paragraph is inserted (in the middle or at the end), the formatting is kept. On pressing Return/Enter again (to insert an empty paragraph), no new paragraph is inserted, the cursor does not move. However, the formatting (e.g. alignment, changes to the font) is removed. After that, text (including new paragraphs) can be entered again normally, but they have some default format (left alignment, not bold/italic/underline, default font).

      Expected behavior: On pressing Enter/Return in an empty paragraph, a new line/paragraph is inserted and the formatting is kept.

      To reproduce: compile the textedit example of Qt (https://code.qt.io/cgit/qt/qtbase.git/tree/examples/widgets/richtext/textedit?h=6.5.1) Move the cursor to the end of the first paragraph, press Enter/Return, press Enter/Return again: no new line/paragraph is inserted, but the formatting of the previous paragraph is removed (easily noticeable in the paragraph-alignment).

      QTBUG-119863 describes this behaviour as well, though uncomplete.

      This behavior started in 6.3; versions up to 6.2 don't seem to be affected.

      It appears to be caused by the handling of key-presses in qwidgettextcontrol.cpp. (https://github.com/qt/qtbase/blob/dev/src/widgets/widgets/qwidgettextcontrol.cpp#L3216C1-L3216C1)

      According to the comment, the behavior is intended to end a list, block quote etc. by hitting enter twice. However, it is poorly implemented: It remove formatting in way too many cases. The behavior is also not documented in the QTextEdit-documentation. Furthermore, it should be configurable through AutoFormatting-Flags.

      Suggestion: Remove Lines 3216 - 3232 from qwidgettextcontrol.cpp for the time being.

      Workaround: Use 6.2

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              chris_p Chris Cross
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes