@leaveye
2018-02-07T12:37:14.000000Z
字数 1586
阅读 887
FAQ
w1801
来自 http://amin-ahmadi.com/2016/09/23/qt-application-fonts-missing-or-invisible-in-linux-fixed/
First create a Qt Resource file and add your font into it.
Let’s assume that our font is Ubuntu’s default Ubuntu-R.ttf
file, then we need to add the following into our main.cpp
QFontDatabase::addApplicationFont(“://Ubuntu-R.ttf”);
qApp->setFont(QFont(“Ubuntu”, 11, QFont::Normal, false));
You should have your fonts back.
two possible solution: [^so12179548]
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...
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?
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);