标签:字体 odi class bug data tap man icons 窗体显示
一、利用字符映射表segmdl2.ttf,窗体显示字符图片。
在win10里面搜“字符映射表”,选择字体segmdl2.ttf,查看图标对应得16进制值。把此字体拷贝到程序的目录下。
二、使用
#ifndef FONTICONS_H #define FONTICONS_H #include <QFont> #include <QObject> //字符映射表 segmdl2.ttf class FontIcons { public: enum IconsId{ ICONS_SCAN=0xE294, ICONS_BROWSE=0xE7C5, ICONS_IMAGE_ACQ=0xE722, ICONS_PARAM_SET=0xE713, ICONS_PREVIEW_IMAGE=0xE7B3, ICONS_EXIT_APP=0xE8BB, ICONS_MODIFY=0xE104, ICONS_CONFIRM_MODIFY=0xE0E7, ICONS_LEFT_ARROW=0xF744, ICONS_RIGHT_ARROW=0xF745, ICONS_ABOUT_APP=0xE19F, ICONS_EXIT_PALLET=0xE176,//退出托盘 ICONS_MANGNIFY=0xE8A3, }; static FontIcons *getInstance(); void init(); void setFontSize(int size); QFont getFont(); QChar getIconChar(FontIcons::IconsId code); QString getIconText(FontIcons::IconsId code,QString text); private: FontIcons(); static FontIcons* instance_; QFont font_; int fontSize_; }; #endif // FONTICONS_H
#include "fonticons.h" #include <QFontDatabase> #include <QDebug> FontIcons* FontIcons::instance_ = new FontIcons; FontIcons::FontIcons() { } FontIcons* FontIcons::getInstance() { return instance_; } void FontIcons::init() { int fontId = QFontDatabase::addApplicationFont(":/three_parts/Fonts/segmdl2.ttf"); QStringList fontFamilies = QFontDatabase::applicationFontFamilies(fontId); font_.setFamily(fontFamilies.at(0)); } void FontIcons::setFontSize(int size) { font_.setPointSize(size); } QFont FontIcons::getFont() { return font_; } QChar FontIcons::getIconChar(FontIcons::IconsId code) { return QChar((int)code); } QString FontIcons::getIconText(FontIcons::IconsId code, QString text) { QString txt = QString("%1%2").arg(getIconChar(code)).arg(text); return txt; }
应用:
QPushButton *btnNavExitApp=new QPushButton(this); FontIcons *fontIcons=FontIcons::getInstance(); fontIcons->init(); fontIcons->setFontSize(14); btnNavExitApp->setText(fontIcons->getIconText(FontIcons::ICONS_EXIT_APP,QString::fromLocal8Bit(" 退出应用")));
标签:字体 odi class bug data tap man icons 窗体显示
原文地址:https://www.cnblogs.com/ike_li/p/11738536.html