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

How to get the systems default sans serif monospace font?



  • Hi,

    Under Linux, when I create font and setFixedPitch on it, and get a nice monospaced font with no serifs. Under Windows I get Courier New. If I set styleHint() the font changes to non-fixed width.

    How can I get a fixed-width (monospaced) non-serif font under Windows (actually, all platforms).

    Gerald

    This doesn't work:

    QFont font("Mono", 12);
    font.setFixedPitch(true);
    font.setStyleHint(QFont::SansSerif);
    

  • Lifetime Qt Champion

    Hi,

    You should add which version of Qt you are using on each platform.



  • Sorry, 5.14.1, I believe..

    I just told both Linux and Windows to load the Consolas font, and it works. Linux uses Deja Vu Sans Mono instead.

    Gerald


Log in to reply