I am building a desktop app using Qt, my dev machine is win 7 x64 with japanese locale, standard system font is Meiryo. Most of win 7 UI is in this font, though classic/older programs such as ui font customization window itself uses different font which is MS UI Gothic. This doesn't bother me until I found that QtCreator builds my app with MS UI Gothic in one place, and Meiryo in the other. For example, qlabels, qlineedits, qcombobox all uses MS UI Gothic, but a custom completer with a qtableview i add later uses Meiryo.
I made most of the UI in QtCreator's Designer, and the completer I added in code. If I change all widgets' font to Meiryo in The Designer, then of course the app will use Meiryo therefore look right, but in this case I'd rather Qt pick whatever system's default font automatically for me because win 7 will not be the only platform I'll use this program.
What raised my concern even more is that QApplication::font() returns MS UI Gothic, which is false in my case. Of course I can set app-wide font using QApplication::setFont() but that defeats the whole purpose of having the native look-n-feel without micromanaging fonts.
So my question is,
Some clarifications and facts I found
I want my app to use system default font for EVERY text.
This discussion said that Designer will add font info regardless whether you want it or not. So Qt will honor this info rather than system default font. At least someone mentioned removing this information manually should make Qt pick system default font in runtime.
In my dev machine QApplication::font() returns WRONG default font. BUT how come a QTableView I add later in code uses RIGHT font? Where did it get this info?
So if I find where QTableView finds this info, I can get it in main, and set it app wide with QApplication::setFont(). Then what's left is manually removing all font info, then HOPEFULLY it will work. But this is like why we use Qt in the first place isn't it?
Simply use the setFont() method on the QApplication or QWidget : QFont font("Courier New"); font. setStyleHint(QFont::Monospace); QApplication::setFont(font);
Windows 10's default system font, Segoe UI, looks pretty nice. However, if you have something better to replace it with, you can change the default system font on your Windows 10 PC.
On your device, open the Settings app. Search and select Font size. To change your preferred font size, move the slider left or right.
I can think of two possible solution:
You could pack with your application a font as a resource file, this way all platforms will use that font regardless the current systems default font.
The QFont class has a method called defaultFamily()
. Using this you could manually set the default font for your whole QApplication
.
An example (main method):
QApplication application(argc, argv);
QFont font;
font.setFamily(font.defaultFamily());
application.setFont(font);
...rest of your code...
Qt will call Windows API SystemParametersInfo
to get fonts for QMenu
, QMessageBox
etc. , and use GetStockObject
to get default system font. Some widgets have special font which is different to system default one. I think Qt is doing the right thing, but the default Japanese/Chinese serif font looks bad on HiDPI monitors.
Just use QFont QApplication::font ( const char * className )
to get the right font (Meryo in your case), such as qApp->setFont(QApplication::font("QMenu"))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With