-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (48 loc) · 1.66 KB
/
main.cpp
File metadata and controls
55 lines (48 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include "mainwindow.h"
#include <QApplication>
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
#include <QtCore5Compat/QTextCodec>
#else
#include <QTextCodec>
#endif
#include <QDebug>
#include <QFontDatabase>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QString dir = QCoreApplication::applicationDirPath();
QStringList m_fontList;
m_fontList.clear();
qDebug() << "Dir is " + dir;
int lcdFontId = QFontDatabase::addApplicationFont(dir + "/simhei.ttf"); // the simhei.ttf is from windows system(%windir%\fonts)
if (lcdFontId != -1)
{
qDebug() << "fond simhei.ttf";
m_fontList << QFontDatabase::applicationFontFamilies(lcdFontId);
}
if (!m_fontList.isEmpty()) // first way: put fonts in directory same with program.
{
QFont font;
font.setFamily(m_fontList.at(0));
a.setFont(font);
qDebug() << "Set simhei font";
}else{ // second way: put fonts in system fonts directory.
QFont font;
font.setPointSize(30);
// *.ttf need be putted in /usr/lib/fonts directory. the *.ttf file can be got from windows (%windir%\fonts)
// after you putted the fonts file, push "Debug" can get the font name from qDebug output.
// then you can use the Name in follow codes. such as:
// Now is chinese font:
// "FangSong"
// "KaiTi"
// "SimHei"
font.setFamily("FangSong"); //simfang.ttf
//font.setFamily("KaiTi"); //simkai.ttf
//font.setFamily("SimHei"); //simhei.ttf
a.setFont(font);
}
MainWindow w;
w.show();
w.showFullScreen();
return a.exec();
}