Where does Qt get the default application font?
I am working on an application and I am having some issues with the style of it. I am on a Linux system, running Red Hat Enterprise Linux 7.4 and KDE Plasma. In Plasma, I have checked my font settings and the standard there is "Sans Serif 10". All other fonts are either smaller or the same size.
However, when I do this:
qDebug() << QApplication::font();
I get this result:
QFont( "Sans Serif,12,-1,5,50,0,0,0,0,0" )
which makes me wonder, where Qt gets its default font from and how I can influence it. The Qt documentation states pretty clearly not to use the
QApplication::setFont()method together with style sheets. Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?
I dont have answer on your question Where does Qt get the default application font?, but i advice for you one way for your question: Where I am trying to get to is to set relative font sizes with the stylesheet and allow the user to select his base size from which the relative sizes are then derived. Is there a way to get there?
- create a one (dialog or widget) form named by Configuration. Create a your design where you will have a list of the fonts that you are giving customers.
- Also give them the opportunity to choose the size of the font.
The good thing is that we can change the font when application is running.
It is a example, how to install the font for our application:
int id = QFontDatabase::addApplicationFont(":/SMSicons/segoeui_0.ttf"); QString family = QFontDatabase::applicationFontFamilies(id).at(0); QFont _font(family, 8); qApp->setFont(_font);
@Taz742 thanks for your response.
I do know how to set the application font, and I do have a QFontDialog in my application right now to do that. However, Qt documentation states not to use
qApp->setFont()in connection with Stylesheets.
Since stylesheets cannot deal with relative font-size anyway, I am focusing on letting the user chose his base font and the stylesheet simply add emphasis (bold, italic,...) where required. However, my concern is about the startup, when the user does not select a font. I believe it is best practice to use the default system font, but it doesn't look like my Qt application is pulling what I think should be the default system font but something else instead. And I wonder, where this 'something else' might come from so I can handle it.
It would also be nice if one of the "experts" in this forum answered this thread, as it seems pretty difficult to understand where Qt (5, at least) actually does pick up its default fonts from under various OSes....
IIRC, on Linux, it comes from FontConfig.
And under Windows it comes from .... magic ??
@SGaist LOL, that's how it looks like
Also see the QApplication::font() methods for gathering the different fonts for different widget types.