How to specify monospace fonts for cross platform Qt applications?

后端 未结 4 1881
夕颜
夕颜 2020-12-05 08:57

Is there a platform independent way to specify a fixed width font for a Qt widget ?

If I set the font to \"Monospace\" in Designer on Linux, it is not found on Windo

4条回答
  •  甜味超标
    2020-12-05 09:31

    You can use the style hint property of QFont:

    QFont font("Monospace");
    font.setStyleHint(QFont::TypeWriter);
    

    If the font cannot be found (which happens with Monospace on Windows), Qt's font matching algorithm tries to find a font that matches the given style hint.

提交回复
热议问题