Qt 使用阿里图标库
#include "widget.h"
#include "ui_widget.h"
#include <QFontDatabase>
Widget::Widget(QWidget *parent)
: QWidget(parent)
, ui(new Ui::Widget)
{
ui->setupUi(this);
this->setStyleSheet("background:#FAFAFA");
int fontId = QFontDatabase::addApplicationFont(":/font/iconfont.ttf"); //加入字体,并获取字体ID
QString fontName = QFontDatabase::applicationFontFamilies(fontId).at(0); //获取字体名称
QFont iconFont = QFont(fontName);
iconFont.setPixelSize(36);
ui->pLabel->setFont(iconFont);
ui->pLabel->setText(QChar(0xe651));
ui->pLabel->setStyleSheet("color:#a90afe;background:#eee");
ui->pLabel->resize(54,54);
ui->pLabel_2->setFont(iconFont);
ui->pLabel_2->setText(QChar(0xeb2d));
ui->pLabel_2->setStyleSheet("color:skyblue;background:#eee");
ui->pLabel_2->resize(54,54);
ui->pLabel_3->setFont(iconFont);
ui->pLabel_3->setText(QChar(0xeb2c));
ui->pLabel_3->setStyleSheet("color:#fc5531;background:#eee");
ui->pLabel_3->resize(54,54);
iconFont.setPixelSize(30);
ui->pushButton->setFont(iconFont);
ui->pushButton->setText(QChar(0xe61d));
ui->pushButton->setStyleSheet("QPushButton{color:purple;border:0 solid #FFF;background:#eee}"\
"QPushButton:hover{color:red}"\
);
ui->pushButton->resize(54,54);
}
- 注:其中setText(QChar(0xeb2c)); 中的 0xeb2c可以通过下载解压打开的demo_index.html进行查看