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

QGraphicsTextItem's initial char format doesn't match the item's rich text

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.8.1
    • GUI: Text handling
    • None
    • Linux/X11

    Description

      I'm writing a GUI editor based on QGraphicsView. When the user selects a text item, I show the current font properties in the GUI, e.g. I show the font size in the font-size-combobox.
      However, the initial font size is 0, even for a text item with contents.

          QGraphicsTextItem item;
          item.setHtml("<html><span style=\" font-size:18pt;\">BIG</span>");
          auto cursor = item.textCursor();
          QCOMPARE(cursor.charFormat().fontPointSize(), 18); // fails, I get 0
      

      This comes from cursor.setCharFormat(charFormatForInsertion); in QWidgetTextControlPrivate::setContent.
      The comment above the initialization of charFormatForInsertion says this is "for use when called from setPlainText" but it's used with rich text content too.

      If I remove that line, it fixes this bug, as well as QTBUG-120044, but it breaks tst_QTextEdit::setPlainTextShouldUseCurrentCharFormat() (see comment in QTBUG-120044).
      For QTextEdit it's arguable what should happen, but for this QGV testcase I think it's very clear that it's bug.

      cursor.setCharFormat(default constructed char format) changes cursor.d->currentCharFormat from -1 to 0, so it stops looking at what the first character actually looks like.
      A hack like cursor.movePosition(QTextCursor::Left) (which is a no-op given that the cursor is at position 0!) sets currentCharFormat to -1 again and fixes the QCOMPARE above... So maybe the fix is to resolve again after setHtml specifically....

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            dfaure_kdab David Faure
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes