Today I was wondering if I could use Font Awesome with Qt’s QML to add some nice looking icons to my buttons. A quick google search brought up an article “Using Fonts Awesome in QML” by markg85 at Mark’s KDE Blog. Mark came up with a nice solution that uses a javascript dictionary to store the icon names with their corresponding unicode character:
However, this has two problems.
The names in the javascript file do not match the definitions on fontawesome.github.io.
The defintions are outdated and do neither include the latest icons nor alias names.
To fix both issues, I wrote a small python script, which will visit https://fontawesome.com/icons, extract all icon names and the corresponding icon pages (for example https://fontawesome.com/icons/cogs) and load the unicode associated with this icon name from the icon page:
This will generate a file in the current working directory called fontawesome.js with the following content (shorted):
The resulting javascript file could be loaded and accessed within the *.qml file as Mark described in his Blog Post:
The above QML code should produce the following output:
That’s it. Enjoy and until next time: Keep coding!
Phidelux is a Computer Science MSc. interested in hardware hacking, embedded Linux, compilers, etc.