fontawesome是一個圖標的集合,裏面有好多的圖標,使用起來也仍是很是方便的。
圖標信息能夠到官網去查:http://fontawesome.io/cheatsheet/
fontawesome-webfont.ttf 下載地址:http://pan.baidu.com/s/1sjyvp3vweb
下面的這個類是網絡上的,我也找不到究竟是誰的了。😄網絡
//iconhelper.happ
#ifndef ICONHELPER_H #define ICONHELPER_H #include <QObject> #include <QFont> #include <QFontDatabase> #include <QMutex> #include <QLabel> #include <QPushButton> #include <QApplication> #include <QTreeWidgetItem> class IconHelper : public QObject { private: explicit IconHelper(QObject *parent = 0); QFont iconFont; static IconHelper* _instance; public: static IconHelper* Instance() { static QMutex mutex; if(!_instance) { QMutexLocker locker(&mutex); if(!_instance) { _instance = new IconHelper; } } return _instance; } void SetIcon(QLabel* lab, QChar c, int size = 10); void SetIcon(QPushButton* btn, QChar c, int size = 10); }; #endif // ICONHELPER_H</pre>
//iconhelper.cppcode
#include "iconhelper.h" IconHelper* IconHelper::_instance = 0; IconHelper::IconHelper(QObject *) : QObject(qApp) { int fontId = QFontDatabase::addApplicationFont(":/image/fontawesome-webfont.ttf"); QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0); iconFont = QFont(fontName); } void IconHelper::SetIcon(QLabel *lab, QChar c, int size) { iconFont.setPointSize(size); lab->setFont(iconFont); lab->setText(c); } void IconHelper::SetIcon(QPushButton *btn, QChar c, int size) { iconFont.setPointSize(size); btn->setFont(iconFont); btn->setText(c); }</pre>
//調用方式ci
QPushButton * Btn = new QPushButton(widget); IconHelper::Instance()->SetIcon(Btn, QChar(0xf192), 12);</pre>