Skip to content

Commit f87ac13

Browse files
committed
Add QmlFontAwesome
1 parent 071e96e commit f87ac13

File tree

9 files changed

+2424
-0
lines changed

9 files changed

+2424
-0
lines changed

QmlFontAwesome/Font/font-awesome.css

Lines changed: 2337 additions & 0 deletions
Large diffs are not rendered by default.
162 KB
Binary file not shown.

QmlFontAwesome/QmlFontAwesome.pro

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#-------------------------------------------------
2+
#
3+
# Copyright (C) 2003-2103 CamelSoft Corporation
4+
#
5+
#-------------------------------------------------
6+
7+
QT += qml quick
8+
9+
CONFIG += c++11
10+
11+
SOURCES += main.cpp
12+
13+
RESOURCES += qml.qrc

QmlFontAwesome/main.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*!
2+
*@file main.cpp
3+
*@brief 程序主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
#include <QGuiApplication>
9+
#include <QQmlApplicationEngine>
10+
#include <QFontDatabase>
11+
#include <QDebug>
12+
13+
int main(int argc, char *argv[])
14+
{
15+
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
16+
QGuiApplication app(argc, argv);
17+
18+
// 添加字体文件
19+
int fontId = QFontDatabase::addApplicationFont(":/Font/fontawesome-webfont.ttf");
20+
QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
21+
qDebug() << "fontFamilies.size() " << fontFamilies.size();
22+
23+
QQmlApplicationEngine engine;
24+
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
25+
26+
return app.exec();
27+
}

QmlFontAwesome/main.qml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*!
2+
*@file main.qml
3+
*@brief 主文件
4+
*@version 1.0
5+
*@section LICENSE Copyright (C) 2003-2103 CamelSoft Corporation
6+
*@author zhengtianzuo
7+
*/
8+
import QtQuick 2.7
9+
import QtQuick.Controls 2.0
10+
11+
ApplicationWindow {
12+
visible: true
13+
width: 400
14+
height: 300
15+
title: qsTr("Qml使用FontAwesome")
16+
17+
Row{
18+
anchors.centerIn: parent
19+
spacing: 20
20+
21+
Text{
22+
color: Qt.rgba(0, 160, 230, 1.0)
23+
font.family: "FontAwesome"
24+
font.pixelSize: 20
25+
text: "\uf00e"
26+
}
27+
Text{
28+
color: "green"
29+
font.family: "FontAwesome"
30+
font.pixelSize: 30
31+
text: "\uf004"
32+
}
33+
}
34+
}

QmlFontAwesome/qml.qrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<RCC>
2+
<qresource prefix="/">
3+
<file>main.qml</file>
4+
<file>Font/fontawesome-webfont.ttf</file>
5+
</qresource>
6+
</RCC>

QmlFontAwesome/show.jpg

12.2 KB
Loading

QtQuickExamples.pro

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,4 @@ SUBDIRS += QmlCanvasText
3737
SUBDIRS += QmlKey
3838
SUBDIRS += QmlLoader
3939
SUBDIRS += QmlInvertedImage
40+
SUBDIRS += QmlFontAwesome

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,3 +167,9 @@ QmlInvertedImage: Qml倒影
167167

168168
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlInvertedImage/show.jpg?raw=true)
169169

170+
171+
QmlFontAwesome: Qml使用FontAwesome
172+
173+
![](https://github.com/zhengtianzuo/QtQuickExamples/blob/master/QmlFontAwesome/show.jpg?raw=true)
174+
175+

0 commit comments

Comments
 (0)