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

changing QFont substitution won't update QML Text

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.5.5, 6.7
    • GUI: Font handling
    • None

    Description

      please see the attached demo substitutes.zip.

      after clicking the window, the QFont::substitution will flip the orders.

          if (flipped) {
              QFont::insertSubstitutions(QStringLiteral("Cambria"),
                                         QStringList() << QStringLiteral("Yu Gothic UI") << QStringLiteral("SimSun"));
              flipped = false;
          } else {
              QFont::insertSubstitutions(QStringLiteral("Cambria"),
                                         QStringList() << QStringLiteral("SimSun") << QStringLiteral("Yu Gothic UI"));
              flipped = true;
          }
      

      you can see the debug output, the substitutions are changed but the text won't update.

      workaround:

      The easiest way would be to add a call to

      QPlatformFontDatabase::repopulateFontDatabase();

      at the end of the changeFont() function. This invalidates everything and forces the render thread to update and it appears to work for me.

      Unfortunately, it means depending on Qt6::GuiPrivate. This is QPA API, so it's considered "semi-public", meaning that we do not guarantee source/binary compatibility but aim to keep it as stable as possible.

      To do the same with public API, you would have to load an application font and then remove it again (basically include some font file in the application and do: int id = QFontDatabase::addApplicationFont("myfile.ttf"); QFontDatabase::removeApplicationFont(id);

      That would trigger the same invalidation, but at the cost of loading a font file. Not very nice, but might be acceptable as a temporary solution until a fix has been made, if depending on semi-public APIs is not acceptable.

      Attachments

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

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            jiu shanheng jiu
            Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes