zoukankan      html  css  js  c++  java
  • 在Qt中使用Font Awesome图标

    官网: http://fontawesome.io/
    中文网: http://www.fontawesome.com.cn/
    GitHub: https://github.com/FortAwesome/Font-Awesome
    1 首先我们从官网(http://www.fontawesome.com.cn/)或者GitHub上下载到最新的源码
    2 在解压目录中找到 fontsfontawesome-webfont.ttf 拷贝出来,这个是我们Qt程序使用FontAwesome图标字体库时需要加载的
    3 然后在css目录下找到font-awesome.css这个是我们开发时需要对字体编码进行查找用的
    4 在官网的 http://fontawesome.io/icons/ 页面可以查看所有的图标, 挑选我们需要的
    使用时比如我们需要用这个心形的图标

    其名称为heart, 那么在font-awesome.css中我们通过查找就可以得到它对应的字体编码

    其字体编码为 f004
    后面我们代码中会用到这个
    也有更方便的方式: 官网直接查看字体编码 http://fontawesome.io/cheatsheet/

    QT使用方法:

    //test
        QLabel *label1 = new QLabel;
        QLabel *label2 = new QLabel;
        int fontId = QFontDatabase::addApplicationFont("/home/qilin64//Documents/Git/qt-gui-elements/TableToolBox-footer/QTableTest/QTableTest/Resouces/fontawesome-webfont.ttf");
        QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId);
        qDebug() << "fontFamilies.size() " << fontFamilies.size();
    
        // 创建字体
        QFont font;
        font.setFamily(fontFamilies.at(0));
        font.setPointSize(20);
    
        // 设置字体及样式、大小
        label1->setFont(font);
        label1->setText(QChar(0xf00e)); //该图标在font-awesome.css文件中查找定义
        label1->setStyleSheet("color: rgb(0, 160, 230);");
    
        QString str = QString("%1%2").arg(QChar(0xf014)).arg(" 删除");
        font.setPointSize(12);
        label2->setFont(font);
        label2->setText(str);
        label2->setStyleSheet("color: rgb(0 , 167 , 252);");
    
        QPushButton *btn = new QPushButton;
        btn->setFont(font);
        btn->setText(str);
        btn->setFlat(true);
        btn->setFocusPolicy(Qt::NoFocus);
        //end test
  • 相关阅读:
    linux之ftp命令详解
    ubuntu-18.04 设置开机启动脚本
    web端调起Windows系统应用程序(exe执行文件),全面兼容所有浏览器
    logstash 6.6.0 读取nginx日志 插入到elasticsearch中
    微服务架构中服务注册与发现
    logstash kafka output 日志处理
    filebeat输出到kafka
    nginx优化之request_time 和upstream_response_time差别
    利用ldirectord实现lvs后端realserver健康状态检查
    ELK 架构之 Logstash 和 Filebeat 安装配置
  • 原文地址:https://www.cnblogs.com/whwywzhj/p/10443576.html
Copyright © 2011-2022 走看看