Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Get the writing system for the application font?



  • I have created my own font combo box class because I needed more control over the fonts displayed. This is for an application which is designed to be i18l ready.

    However, I need to populate the list of font families according to the desired writing system (enum values as defined in QFontDatabase), otherwise I get dozens, if not hundreds, of symbol fonts and fonts in many different languages which can be tiresome to scroll through.

    Is there a way to do this by querying some system info? I can just define QFontDatabase::Latin, for example, as a constant in my code, but what if someone wants to use the app with some language which uses a non-Latin writing system? I want to avoid having to change the source code, if possible, and query the information at runtime.



  • @Robert-Hairgrove

    Just filter your font list by using
    https://doc.qt.io/qt-5/qfontdatabase.html#families

    then populate your comboBox with your filtered list.

    To add more families with different wrinting systems at runtime, you could add checkBoxes and add the according families to your list (and to your font comboBox).



  • @Pl45m4 Thanks, but I am doing this already. The issue is WHICH filter to use, decided at runtime?

    I suppose I could hard-code a lookup table depending on the current language, but it would be much easier to get this information directly from the operating system language, or include it in the configuration file (there will never be more than a few languages, anyway).



  • Now I am going ahead by adding an attribute to the configuration file which explicitly matches the writing system with any language which can be selected. The user can change the language as well as the application font in the settings dialog. If the current font is compatible with the new language selected, it will continue to be used; otherwise, the system font will be used, and the user will be prompted to choose a different font if so desired.

    It would be better to query the system for an appropriate writing system, however. Therefore, I am not marking this as solved just yet.


Log in to reply