2022-12-28 03:49:56 +08:00
# QtAwesome - Font Awesome for Qt Applications
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
QtAwesome is a library to add [Font Awesome ](http://fortawesome.github.io/Font-Awesome/ )
icons to your [Qt application ](http://qt-project.org/ ).
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
## Table of Contents
2014-06-12 20:45:47 +08:00
2023-02-09 18:53:16 +08:00
- [Latest Release 6.3.0 ](#latest-release-630 )
- [Font Awesome 6 Release ](#font-awesome-6-release )
2022-12-27 23:01:09 +08:00
- [Installation Free Version ](#installation-free-version )
- [Installation Pro version ](#installation-pro-version )
- [Basic Usage ](#basic-usage )
- [Examples ](#examples )
2022-12-28 03:49:56 +08:00
- [Example Custom Painter ](#example-custom-painter )
2022-12-27 23:01:09 +08:00
- [Default options ](#default-options )
- [Known Issues And Workarounds ](#known-issues-and-workarounds )
2022-12-28 03:49:56 +08:00
- [Summary of Changes ](#summary-of-changes )
2022-12-27 23:01:09 +08:00
- [Thanks ](#thanks )
- [Contact ](#contact )
- [License ](#license )
2013-04-19 14:26:54 +08:00
2023-02-09 18:53:16 +08:00
## Latest Release 6.3.0
Support for "Font Awesome Sharp Regular" (Pro) icons.
All alias-names are now added to the to the icon-name map.
[View changelog ](CHANGES.md )
## Font Awesome 6 Release
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
This is the Font Awesome 6 release. It replaces the main branch, which still was a Font Awesome 4 version.
(There's also a Font Awesome 5 branch, but was never merged to the main/master branch.)
2019-09-06 04:26:37 +08:00
2022-12-27 23:01:09 +08:00
This release is **not** completely backwards compatible with the 4 and 5 releases.
The decision was made for a new clean version which better suited for the future.
(A compatibility layer is in development).
2019-09-06 04:26:37 +08:00
2022-12-27 23:01:09 +08:00
Previous versions used a hand-crafted icon list, this version has a generated list.
2014-05-08 02:10:57 +08:00
2022-12-27 23:01:09 +08:00
Having troubles with this new release?
2014-05-08 02:10:57 +08:00
2022-12-27 23:01:09 +08:00
- You can find the previous `master` branch in the [fontawesome-4 ](https://github.com/gamecreature/QtAwesome/tree/fontawesome-4 ) branch. (`master` is dropped in favour of `main` )
- The [fontawesome-5 ](https://github.com/gamecreature/QtAwesome/tree/fontawesome-5 ) branch contains the Font Awesome 5 version.
- The new [main ](https://github.com/gamecreature/QtAwesome/ ) branch contains the latest Font Awesome 6 version.
- Open a github issue if you'v found a bug or have a suggestion
2014-05-08 02:10:57 +08:00
2022-12-27 23:01:09 +08:00
## Installation Free Version
2017-11-27 23:32:49 +08:00
2022-12-27 23:01:09 +08:00
The easiest way to include QtAweome in your project is to copy the QtAwesome directory to your
project tree and add the following `include()` to your Qt project file:
2015-03-20 04:21:38 +08:00
2022-12-27 23:01:09 +08:00
```bash
CONFIG+=fontAwesomeFree
include(QtAwesome/QtAwesome.pri)
```
2015-03-20 04:21:38 +08:00
2022-12-27 23:01:09 +08:00
Now you are good to go! The free fonts are included in this project.
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
## Installation Pro version
2022-12-28 20:53:57 +08:00
To activate the pro version, `fontAwesomePro` config should be defined.
2013-04-19 14:26:54 +08:00
2019-09-07 19:15:11 +08:00
```bash
2022-12-27 23:01:09 +08:00
CONFIG+=fontAwesomePro
2019-09-07 19:15:11 +08:00
include(QtAwesome/QtAwesome.pri)
```
2013-04-19 14:26:54 +08:00
2022-12-28 20:53:57 +08:00
And the pro font files need to be copied to the `QtAwesome/fonts/pro` folder.
2022-12-27 23:01:09 +08:00
(ex, Font Awesome 6 Brands-Regular-400.otf, etc... )
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
## Basic Usage
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
You probably want to create a single QtAwesome object for your whole application.
2013-04-19 14:26:54 +08:00
2019-09-07 19:15:11 +08:00
```c++
2022-12-27 23:01:09 +08:00
fa::QtAwesome* awesome = new fa::QtAwesome(qApp)
2019-09-07 19:15:11 +08:00
awesome->initFontAwesome(); // This line is important as it loads the font and initializes the named icon map
```
2013-04-23 12:16:38 +08:00
2022-12-27 23:01:09 +08:00
- Add an accessor to this object (i.e. a global function, member of your application object, or whatever you like).
- Use an icon name from the [Font Awesome Library ](https://fontawesome.com/icons ).
## Examples
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
Next the icons can be accessed via the `awesome->icon` method.
2017-11-27 23:32:49 +08:00
2013-04-19 19:09:36 +08:00
```c++
2022-12-27 23:01:09 +08:00
// The most performant operation the get an icon
QPushButton* btn = new QPushButton(awesome->icon(fa::fa_solid, fa::fa_wine_glass), "Cheers!");
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
// You can also use 'string' names to access the icons.
QPushButton* btn = new QPushButton(awesome->icon("fa-solid fa-coffee" ), "Black please!");
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
// The string items passed to the icon method can be used without the 'fa-' prefix
QPushButton* btn = new QPushButton(awesome->icon("solid coffee" ), "Black please!");
// The style is also optional and will fallback to the 'solid' style
QPushButton* btn = new QPushButton(awesome->icon("coffee" ), "Black please!");
```
For shorter syntax (more Font Aweseome like) is possible to bring the fa namespace into the curren scope:
```c++
using namespace fa;
QPushButton* btn = new QPushButton(awesome->icon(fa_solid, fa_wine_glass), "Cheers!");
```
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
It is possible to create some extra options for the icons.
The available options can be found in the [Default options list ](#default-options )
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
```c++
2013-04-19 19:09:36 +08:00
QVariantMap options;
2022-12-27 23:01:09 +08:00
options.insert("color" , QColor(255, 0 ,0));
QPushButton* musicButton = new QPushButton(awesome->icon(fa::fa_solid, fa::music, options), "Music");
```
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
The defaults option can also be adjusted via the `setDefaultOption` method.\
For example having green disabled icons, it is possible to call:
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
```c++
awesome->setDefaultOption("color-disabled", QColor(0, 255, 0));
```
2013-04-19 19:09:36 +08:00
2022-12-27 23:01:09 +08:00
It also possible to render a label directly with this font
```c++
QLabel* label = new QLabel(QChar(fa::fa_github));
label->setFont(awesome->font(fa::fa_brands, 16));
2013-04-19 19:09:36 +08:00
```
2022-12-28 03:49:56 +08:00
## Example Custom Painter
2013-04-19 19:09:36 +08:00
2022-12-27 23:01:09 +08:00
This example registers a custom painter for supporting an custom icon named 'duplicate'
It simply draws 2 "plus marks".
2013-04-19 19:09:36 +08:00
```c++
class DuplicateIconPainter : public QtAwesomeIconPainter
{
public:
2022-12-27 23:01:09 +08:00
virtual void paint(QtAwesome* awesome, QPainter* painter, const QRect& rectIn, QIcon::Mode mode, QIcon::State state, const QVariantMap& options)
2013-04-19 19:09:36 +08:00
{
2022-12-27 23:01:09 +08:00
int drawSize = qRound(rectIn.height() * 0.5);
2013-04-19 19:09:36 +08:00
int offset = rectIn.height() / 4;
2022-12-27 23:01:09 +08:00
QChar chr = QChar(static_cast< int > (fa::plus));
int st = fa::fa_solid;
2013-04-19 19:09:36 +08:00
2022-12-27 23:01:09 +08:00
painter->setFont(st, awesome->font(drawSize));
2013-04-19 19:09:36 +08:00
2022-12-27 23:01:09 +08:00
painter->setPen(QColor(100,100,100));
painter->drawText(QRect(QPoint(offset * 2, offset * 2),
QSize(drawSize, drawSize)), chr ,
QTextOption(Qt::AlignCenter|Qt::AlignVCenter));
2013-04-19 19:09:36 +08:00
2022-12-27 23:01:09 +08:00
painter->setPen(QColor(50,50,50));
painter->drawText(QRect(QPoint(rectIn.width() - drawSize-offset, rectIn.height() - drawSize - offset),
QSize(drawSize, drawSize) ), chr ,
QTextOption(Qt::AlignCenter | Qt::AlignVCenter));
2013-04-19 19:09:36 +08:00
}
};
2022-12-27 23:01:09 +08:00
awesome->give("duplicate", new DuplicateIconPainter());
```
After this, this icon can be used with the given string name:
```c++
awesome->icon("duplicate")
2013-04-19 19:09:36 +08:00
```
2013-04-19 14:26:54 +08:00
2019-09-07 19:15:11 +08:00
## Default options
2017-11-27 23:32:49 +08:00
2022-12-27 23:01:09 +08:00
The following options are the defaults in the QtAwesome class.
2013-04-19 14:26:54 +08:00
2013-04-19 19:09:36 +08:00
```c++
2022-12-27 23:01:09 +08:00
setDefaultOption("color", QApplication::palette().color(QPalette::Normal, QPalette::Text));
setDefaultOption("color-disabled", QApplication::palette().color(QPalette::Disabled, QPalette::Text));
setDefaultOption("color-active", QApplication::palette().color(QPalette::Active, QPalette::Text));
setDefaultOption("color-selected", QApplication::palette().color(QPalette::Active, QPalette::Text));
2013-06-07 20:52:42 +08:00
2022-12-27 23:01:09 +08:00
setDefaultOption("text", QString()); // internal option
setDefaultOption("text-disabled", QString());
setDefaultOption("text-active", QString());
setDefaultOption("text-selected", QString());
2013-06-07 20:52:42 +08:00
2022-12-27 23:01:09 +08:00
setDefaultOption("scale-factor", 0.9);
2019-09-06 04:26:37 +08:00
```
2022-12-27 23:01:09 +08:00
Extra items for the pro version
2019-09-07 19:15:11 +08:00
2019-09-06 04:26:37 +08:00
```c++
2022-12-27 23:01:09 +08:00
setDefaultOption("duotone-color", QApplication::palette().color(QPalette::Normal, QPalette::BrightText));
setDefaultOption("duotone-color-disabled", QApplication::palette().color(QPalette::Disabled, QPalette::BrightText));
setDefaultOption("duotone-color-active", QApplication::palette().color(QPalette::Active, QPalette::BrightText));
setDefaultOption("duotone-color-selected", QApplication::palette().color(QPalette::Active, QPalette::BrightText));
2013-04-19 19:09:36 +08:00
```
2013-04-19 14:26:54 +08:00
2019-09-07 19:15:11 +08:00
When creating an icon, it first populates the options-map with the default options from the QtAwesome object.
After that the options are expanded/overwritten by the options supplied to the icon.
2017-11-27 23:32:49 +08:00
2019-09-07 19:15:11 +08:00
It is possible to use another glyph per icon-state. For example to make an icon-unlock symbol switch to locked when selected,
you could supply the following option:
2013-04-19 14:26:54 +08:00
2017-11-27 23:32:49 +08:00
```c++
2022-12-27 23:01:09 +08:00
options.insert("text-selected", QString(fa::fa_lock));
2013-06-07 20:52:42 +08:00
```
2013-04-19 14:26:54 +08:00
2017-11-27 23:32:49 +08:00
Color and text options have the following structure:
`keyname-iconmode-iconstate`
2022-12-27 23:01:09 +08:00
When iconmode normal is empty\
And iconstate on is blank
2017-11-27 23:32:49 +08:00
So the list of items used is:
2022-12-27 23:01:09 +08:00
- color
- color-disabled
- color-active
- color-selected
- color-off
- color-disabled-off
- color-active-off
- color-selected-off
- duotone-color (pro)
- duotone-color-disabled (pro)
- duotone-color-active (pro)
- duotone-color-selected (pro)
- duotone-color-off (pro)
- duotone-color-disabled-off (pro)
- duotone-color-active-off (pro)
- duotone-color-selected-off (pro)
- text
- text-disabled
- text-active
- text-selected
- text-off
- text-disabled-off
- text-active-off
- text-selected-off
- style
- style-disabled
- style-active
- style-selected
- style-off
- style-disabled-off
- style-active-off
- style-selected-off
## Known Issues And Workarounds
2015-09-25 02:28:15 +08:00
2017-11-27 23:32:49 +08:00
On Mac OS X, placing an qtAwesome icon in QMainWindow menu, doesn't work directly.
2015-09-25 02:28:15 +08:00
See the following issue: [https://github.com/gamecreature/QtAwesome/issues/10]
2022-12-27 23:01:09 +08:00
A workaround for this problem is converting it to a Pixmap icon:
2015-09-25 02:28:15 +08:00
```c++
QAction* menuAction = new QAction("test");
2022-12-27 23:01:09 +08:00
menuAction->setIcon(awesome->icon(fa::fa_heart).pixmap(32,32));
2015-09-25 02:28:15 +08:00
```
2022-12-28 03:49:56 +08:00
## Summary of Changes
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
- The complete icons set is renewed and is generated
- Everything is namespaced in the `fa` namespace
- Icon name enumerations are changed so the full Font Aweomse name is used: `fa::user` => `fa::fa_user` .
With the dashes replaced by underscores.
2022-12-28 03:49:56 +08:00
- Font Awesome 6 full style names, like `fa::fa_regular` , `fa::fa_solid`
2022-12-27 23:01:09 +08:00
- This release has been tested with Qt 5 and Qt 6.
2013-04-19 14:26:54 +08:00
2022-12-27 23:01:09 +08:00
## Thanks
2014-05-08 02:10:57 +08:00
Thanks go to the contributors of this project!
2023-01-17 03:24:45 +08:00
Many thanks go to Dave Gandy an the other Font Awesome contributors!! [https://github.com/FortAwesome/Font-Awesome ](https://github.com/FortAwesome/Font-Awesome )
2013-04-19 14:26:54 +08:00
And of course to the Qt team/contributors for supplying this great cross-platform c++ library.
Contributions are welcome! Feel free to fork and send a pull request through Github.
2022-12-27 23:01:09 +08:00
< a href = "https://github.com/gamecreature/qtawesome/graphs/contributors" >
< img src = "https://contrib.rocks/image?repo=gamecreature/qtawesome" / >
< / a >
< small > *Contribution list made with [contrib.rocks ](https://contrib.rocks ).*</ small >
## Contact
- email: < rick @ blommersit . nl >
- mastedon: [https://ruby.social/@rick ](https://ruby.social/@rick )
- twitter: [https://twitter.com/gamecreature ](https://twitter.com/gamecreature )
2023-01-17 03:24:45 +08:00
- website: [https://gamecreatures.com ](https://gamecreatures.com )
2022-12-27 23:01:09 +08:00
- github: [https://github.com/gamecreature/QtAwesome ](https://github.com/gamecreature/QtAwesome )
## License
2023-01-17 03:24:45 +08:00
MIT License. Copyright 2013-2022 - Reliable Bits Software by Blommers IT. [https://blommersit.nl/ ](https://blommersit.nl )
2022-12-27 23:01:09 +08:00
2023-01-17 03:24:45 +08:00
The Font Awesome font is licensed under the SIL Open Font License - [https://scripts.sil.org/OFL ](http://scripts.sil.org/OFL )
The Font Awesome pictograms are licensed under the CC BY 3.0 License - [https://creativecommons.org/licenses/by/3.0/ ](http://creativecommons.org/licenses/by/3.0/ )
"Font Awesome by Dave Gandy - https://github.com/FortAwesome/Font-Awesome"