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);
-
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
-
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);
@GeraldBrandt, did you ever learn how to ascertain which font aliases correlate to which fonts on Windows? If not, I've recently asked https://webmasters.stackexchange.com/q/145196/122892, but that's solely half of the puzzle, so I'd like to know if possible.
-
@GeraldBrandt, did you ever learn how to ascertain which font aliases correlate to which fonts on Windows? If not, I've recently asked https://webmasters.stackexchange.com/q/145196/122892, but that's solely half of the puzzle, so I'd like to know if possible.
@RokeJulianLockhart You should be able to create a QFont and then use QFontInfo to see what you actually got and whether it was an exact match or not.
{ QFont font("sans serif"); QFontInfo info(font); qDebug() << font; qDebug() << info.exactMatch() << info.family() << info.pointSizeF(); // QFont(sans serif,12,-1,5,50,0,0,0,0,0) // false "Noto Sans" 12 } { QFont font("Noto Sans"); QFontInfo info(font); qDebug() << font; qDebug() << info.exactMatch() << info.family() << info.pointSizeF(); //QFont(Noto Sans,12,-1,5,50,0,0,0,0,0) //true "Noto Sans" 12 false }
The aliases and their mappings vary from Windows version to version.
You could look at Font-name and the registry keyHKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
-
@RokeJulianLockhart You should be able to create a QFont and then use QFontInfo to see what you actually got and whether it was an exact match or not.
{ QFont font("sans serif"); QFontInfo info(font); qDebug() << font; qDebug() << info.exactMatch() << info.family() << info.pointSizeF(); // QFont(sans serif,12,-1,5,50,0,0,0,0,0) // false "Noto Sans" 12 } { QFont font("Noto Sans"); QFontInfo info(font); qDebug() << font; qDebug() << info.exactMatch() << info.family() << info.pointSizeF(); //QFont(Noto Sans,12,-1,5,50,0,0,0,0,0) //true "Noto Sans" 12 false }
The aliases and their mappings vary from Windows version to version.
You could look at Font-name and the registry keyHKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\FontSubstitutes
@ChrisW67, that's brilliant. Thank you. I've found some useful corroberating information at https://superuser.com/a/1512700/904401.