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

QTextCursor::charFormat() reports incorrect results when selecting right to left and left-most char is adjacent to a different format

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.15.0
    • GUI: Text handling
    • None
    • Windows

    Description

      The following is a picture of an application I'm writing for basic text editing.

      In the above image, the text was selected right to left across the larger font size text, which is point size 22. Instead of showing an expected font size of 22 – since the text selection ends before it winds up on the smaller size text – it reports 8.

      The following block of code was used to update the UI to report this. ui.textEdit is a QTextEdit. The top block of code is in a slot to a selectionChanged signal.

      QTextCursor cursor = ui.textEdit->textCursor();
      auto blockFormat = cursor.charFormat();
      if (blockFormat.isValid())
          UpdateFontStyle(blockFormat.font());
      
      void UpdateFontStyle(const QFont& f)
      {
          ui.boldButton->setChecked(f.bold());
          ui.underlineButton->setChecked(f.underline());
          ui.italicButton->setChecked(f.italic());
          auto t = QString::number(f.pointSize()); // edited for width
          ui.fontSizeBox->setCurrentIndex(ui.fontSizeBox->findText(t));
          ui.fontNameBox->setCurrentFont(QFontInfo(f).family());
      }

      If the same text is instead selected by going left to right, or the user double clicks in the larger font text "block" (which is conveniently blocking the double click action from selecting the smaller text by the exclamation point), it still reports 22.

       

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            domiran Ross Lombardi
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes