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/