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

Current font mismatch in QFontComboBox

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P3: Somewhat important
    • None
    • 6.2.0
    • None
    • All

    Description

      When you set an invalid font on a QFontComboBox, the first entry in the list of fonts will be selected by default, and the currentFont() will reflect this.

      But if the first entry is already selected when you do this, we will update the currentFont to match the invalid font and then skip all subsequent updates because the index has not actually changed. So you end up with currentFont() returning the invalid request instead.

      This can be reproduced with the following code:

      #include <QtGui>
      #include <QtWidgets>
      
      int main(int argc, char *argv[])
      {
          QApplication a(argc, argv);
      
          QFontComboBox box;
      
          box.setCurrentFont(QFont("Invalid Font"));
          qDebug() << box.currentFont().family();
      
          box.setCurrentFont(QFont("Another Invalid Font"));
          qDebug() << box.currentFont().family();
      
          return 0;
      }
      

      The example prints out the following on my Windows machine:

      "Arial"
      "Another Invalid Font"
      

      So the first time and invalid font is requested, we select the first valid font instead (Arial). The next time, currentFont() returns the invalid font family instead (this does not match the text in the editor at this point).

      Note: If the first entry happens to be the default (on macOS for instance, since the default font is not available in the list) or if you manually select index 0, the bug will occur on the first call to setCurrentFont() instead.

      Attachments

        Issue Links

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

          Activity

            People

              qt.team.quick.subscriptions Qt Quick and Widgets Team
              esabraha Eskil Abrahamsen Blomfeldt
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes