Font-Awesome is a project that deserves its name ❤️. Since it cannot be expected on distros to be installed, using it in (QML-) projects is a bit tedious. One needs to:
- Get the ttf's into your QML's project resource
- register the fonts
- search for the glyphs wanted
- find a more descripitive way than unicode chars to add icons to the code
To make things more simple this project contains:
- a wrapper library that translates symbolic variable names to unicode and adds a tiny helper function to colorize glyphs
- A viewer-application to search for glyphs and directly copy symbol name into QML-source code.
- A python-script to auto-upgrade symbol-list/model to latest Font-Awesome.
To use this project do
- Download it by
git clone --recursive https://github.com/schnitzeltony/fontawesome-qml.git
- Build it and install it to a location cmake can find it
In your project add:
- In CMakeList.txt:
...
find_package(FontAweSomeQml REQUIRED)
...
target_link_libraries(<your-target>
...
FontAweSomeQml::FontAweSomeQml
...
)
- In main.cpp (for parameters of FontAwesomeQml::registerFonts see fontawesome-qml.h)
#include <fontawesome-qml.h>
...
int main(int argc, char *argv[])
{
QQmlApplicationEngine engine;
...
FontAwesomeQml::registerFonts(false, true, false);
FontAwesomeQml::registerFAQml(&engine);
...
engine.load(url);
return app.exec();
}
- In QML:
...
import FontAwesomeQml 1.0
...
Button {
font.family: FAQ.fontFamily
font.styleName: "Solid" // or "Regular" requires registerFonts(true, ..)
text: FAQ.fa_file
}
...
- In QML / ListElement we cannot use
FAQ.<glyph>
ListElement: cannot use script for property value
see Example:
...
import FontAwesomeQml 1.0
import FontAwesomeHash 1.0
...
ListView {
ListModel {
ListElement {glyph: "fa_moon"; gcolor: "black"; gtext: "Sleep well"}
ListElement {glyph: "fa_sun"; gcolor: "yellow"; gtext: "Most favorite"}
...
}
delegate: Text {
font.family: FAQ.fontFamily
text: FAQ.icon(FAQH.strToGlyph(glyph), gcolor) + gtext
}
}
...
For dependencies check CMakeLists.txt / find_package
.
THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND and licensed under LGPL-3.0 License.