Qtawesome是一个库,可在您的QT应用程序中添加字体真棒图标。
额外的Duotone样式
查看ChangElog
这是字体很棒的6版本。它取代了主分支,该分支仍然是字体很棒的4版。 (还有一个字体很棒的5个分支,但从未合并到主/主分支。)
该版本与4和5版本并不完全兼容。该决定是针对新的清洁版本的决定,该版本更适合未来。 (开发兼容性层)。
以前的版本使用了手工制作的图标列表,此版本具有生成的列表。
这个新版本有麻烦吗?
master分支。 ( master被撤销以支持main )在您的项目中包含Qtaweome的最简单方法是将QTawesome目录复制到您的项目树中,并将以下include()添加到QT项目文件中:
CONFIG+=fontAwesomeFree
include(QtAwesome/QtAwesome.pri)现在你很好!该项目包含免费字体。
要激活Pro版本,应定义fontAwesomePro配置。
CONFIG+=fontAwesomePro
include(QtAwesome/QtAwesome.pri)并且需要将Pro字体文件复制到QtAwesome/fonts/pro文件夹中。 (例如,字体很棒的6个品牌-400.otf等...)
您可能想为整个应用程序创建一个单个QTAWEASE对象。
fa::QtAwesome* awesome = new fa::QtAwesome(qApp)
awesome-> initFontAwesome (); // This line is important as it loads the font and initializes the named icon map接下来,可以通过awesome->icon方法访问图标。
// The most performant operation the get an icon
QPushButton* btn = new QPushButton(awesome-> icon (fa::fa_solid, fa::fa_wine_glass), "Cheers!");
// You can also use 'string' names to access the icons.
QPushButton* btn = new QPushButton(awesome-> icon ( " fa-solid fa-coffee " ), "Black please!");
// 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!");对于较短的语法(更多字体aweseome),可以将FA名称空间带入Curren范围:
using namespace fa ;
QPushButton* btn = new QPushButton(awesome-> icon (fa_solid, fa_wine_glass), "Cheers!");可以为图标创建一些额外的选项。可用选项可以在默认选项列表中找到
QVariantMap options;
options.insert( " color " , QColor( 255 , 0 , 0 ));
QPushButton* musicButton = new QPushButton(awesome-> icon (fa::fa_solid, fa::music, options), "Music");默认选项也可以通过setDefaultOption方法进行调整。
例如,拥有绿色残疾图标,可以致电:
awesome-> setDefaultOption ( " color-disabled " , QColor( 0 , 255 , 0 ));也可以用此字体直接渲染标签
QLabel* label = new QLabel(QChar(fa::fa_github));
label-> setFont (awesome-> font (fa::fa_brands, 16 ));此示例注册了一个自定义画家,用于支持名为“重复”的自定义图标,它只是绘制2个“ Plus Marks”。
class DuplicateIconPainter : public QtAwesomeIconPainter
{
public:
virtual void paint (QtAwesome* awesome, QPainter* painter, const QRect& rectIn, QIcon::Mode mode, QIcon::State state, const QVariantMap& options)
{
int drawSize = qRound (rectIn. height () * 0.5 );
int offset = rectIn. height () / 4 ;
QChar chr = QChar ( static_cast < int >(fa::plus));
int st = fa::fa_solid;
painter-> setFont (st, awesome-> font (drawSize));
painter-> setPen ( QColor ( 100 , 100 , 100 ));
painter-> drawText ( QRect ( QPoint (offset * 2 , offset * 2 ),
QSize (drawSize, drawSize)), chr ,
QTextOption (Qt::AlignCenter|Qt::AlignVCenter));
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));
}
};
awesome-> give ( " duplicate " , new DuplicateIconPainter());之后,该图标可以与给定的字符串名称一起使用:
awesome-> icon ( " duplicate " )以下选项是qtawesome类中的默认值。
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));
setDefaultOption ( " text " , QString()); // internal option
setDefaultOption ( " text-disabled " , QString());
setDefaultOption ( " text-active " , QString());
setDefaultOption ( " text-selected " , QString());
setDefaultOption ( " scale-factor " , 0.9 );专业版本的额外项目
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));创建图标时,它首先使用qtawesome对象的默认选项填充了选项映射。之后,这些选项由提供给图标的选项扩展/覆盖。
每个图标状态都可以使用另一个字形。例如,在选定时将图标unlock符号切换到锁定,您可以提供以下选项:
options.insert( " text-selected " , QString(fa::fa_lock));颜色和文本选项具有以下结构: keyname-iconmode-iconstate
当iConmode正常为空时
和IconState上的是空白
因此,使用的项目列表是:
在Mac OS X上,在QMainWindow菜单中放置一个QTAWESY图标,无法直接工作。请参阅以下问题:[#10]
解决此问题的解决方法是将其转换为PixMap图标:
QAction* menuAction = new QAction( " test " );
menuAction-> setIcon (awesome-> icon (fa::fa_heart).pixmap( 32 , 32 ));fa名称空间中名称fa::user => fa::fa_user 。用破折号取代了下划线。fa::fa_regular , fa::fa_solid感谢该项目的贡献者!
非常感谢Dave Gandy和其他字体很棒的贡献者! https://github.com/fortawesome/font-awesome,当然还有QT团队/贡献者,以提供此出色的跨平台C ++库。
欢迎捐款!随意叉,并通过github发送拉动请求。
贡献清单由贡献。
麻省理工学院许可证。版权所有2013-2022- Blombers IT可靠的BITS软件。 https://blommersit.nl/
字体Awesome Font符合SIL Open Font许可证-https://scripts.sil.org/ofl font Awesome象形图由CC by 3.0许可-3.0许可-https://creativecommons.org/commons.org/commons.org/licenses/by/by/3.0/