更新代码

master
feiyangqingyun 2022-01-22 20:01:44 +08:00
parent 8d94e928a0
commit b0d5ff6ef4
13 changed files with 358 additions and 166 deletions

View File

@ -2,6 +2,7 @@
IconHelper *IconHelper::iconFontAliBaBa = 0; IconHelper *IconHelper::iconFontAliBaBa = 0;
IconHelper *IconHelper::iconFontAwesome = 0; IconHelper *IconHelper::iconFontAwesome = 0;
IconHelper *IconHelper::iconFontAwesome6 = 0;
IconHelper *IconHelper::iconFontWeather = 0; IconHelper *IconHelper::iconFontWeather = 0;
int IconHelper::iconFontIndex = -1; int IconHelper::iconFontIndex = -1;
@ -16,12 +17,20 @@ void IconHelper::initFont()
if (iconFontAwesome == 0) { if (iconFontAwesome == 0) {
iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome"); iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome");
} }
if (iconFontAwesome6 == 0) {
iconFontAwesome6 = new IconHelper(":/font/fa-regular-400.ttf", "Font Awesome 6 Pro Regular");
}
if (iconFontWeather == 0) { if (iconFontWeather == 0) {
iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather"); iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather");
} }
} }
} }
void IconHelper::setIconFontIndex(int index)
{
iconFontIndex = index;
}
QFont IconHelper::getIconFontAliBaBa() QFont IconHelper::getIconFontAliBaBa()
{ {
initFont(); initFont();
@ -34,6 +43,12 @@ QFont IconHelper::getIconFontAwesome()
return iconFontAwesome->getIconFont(); return iconFontAwesome->getIconFont();
} }
QFont IconHelper::getIconFontAwesome6()
{
initFont();
return iconFontAwesome6->getIconFont();
}
QFont IconHelper::getIconFontWeather() QFont IconHelper::getIconFontWeather()
{ {
initFont(); initFont();
@ -48,6 +63,7 @@ IconHelper *IconHelper::getIconHelper(int icon)
//没指定则自动根据不同的字体的值选择对应的类 //没指定则自动根据不同的字体的值选择对应的类
//由于部分值范围冲突所以可以指定索引来取 //由于部分值范围冲突所以可以指定索引来取
//fontawesome 0xf000-0xf2e0 //fontawesome 0xf000-0xf2e0
//fontawesome6 0xe000-0xe33d 0xf000-0xf8ff
//iconfont 0xe501-0xe793 0xe8d5-0xea5d //iconfont 0xe501-0xe793 0xe8d5-0xea5d
//weather 0xe900-0xe9cf //weather 0xe900-0xe9cf
@ -61,6 +77,8 @@ IconHelper *IconHelper::getIconHelper(int icon)
} else if (iconFontIndex == 1) { } else if (iconFontIndex == 1) {
iconHelper = iconFontAwesome; iconHelper = iconFontAwesome;
} else if (iconFontIndex == 2) { } else if (iconFontIndex == 2) {
iconHelper = iconFontAwesome6;
} else if (iconFontIndex == 3) {
iconHelper = iconFontWeather; iconHelper = iconFontWeather;
} }
@ -115,7 +133,7 @@ IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName)) { if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

View File

@ -31,6 +31,18 @@ class IconHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
private:
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//FontAwesome6图形字体类
static IconHelper *iconFontAwesome6;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
public: public:
//样式颜色结构体 //样式颜色结构体
struct StyleColor { struct StyleColor {
@ -90,21 +102,16 @@ public:
} }
}; };
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
//初始化图形字体 //初始化图形字体
static void initFont(); static void initFont();
//设置引用图形字体文件索引
static void setIconFontIndex(int index);
//获取图形字体 //获取图形字体
static QFont getIconFontAliBaBa(); static QFont getIconFontAliBaBa();
static QFont getIconFontAwesome(); static QFont getIconFontAwesome();
static QFont getIconFontAwesome6();
static QFont getIconFontWeather(); static QFont getIconFontWeather();
//根据值获取图形字体类 //根据值获取图形字体类

View File

@ -2,6 +2,7 @@
IconHelper *IconHelper::iconFontAliBaBa = 0; IconHelper *IconHelper::iconFontAliBaBa = 0;
IconHelper *IconHelper::iconFontAwesome = 0; IconHelper *IconHelper::iconFontAwesome = 0;
IconHelper *IconHelper::iconFontAwesome6 = 0;
IconHelper *IconHelper::iconFontWeather = 0; IconHelper *IconHelper::iconFontWeather = 0;
int IconHelper::iconFontIndex = -1; int IconHelper::iconFontIndex = -1;
@ -16,12 +17,20 @@ void IconHelper::initFont()
if (iconFontAwesome == 0) { if (iconFontAwesome == 0) {
iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome"); iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome");
} }
if (iconFontAwesome6 == 0) {
iconFontAwesome6 = new IconHelper(":/font/fa-regular-400.ttf", "Font Awesome 6 Pro Regular");
}
if (iconFontWeather == 0) { if (iconFontWeather == 0) {
iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather"); iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather");
} }
} }
} }
void IconHelper::setIconFontIndex(int index)
{
iconFontIndex = index;
}
QFont IconHelper::getIconFontAliBaBa() QFont IconHelper::getIconFontAliBaBa()
{ {
initFont(); initFont();
@ -34,6 +43,12 @@ QFont IconHelper::getIconFontAwesome()
return iconFontAwesome->getIconFont(); return iconFontAwesome->getIconFont();
} }
QFont IconHelper::getIconFontAwesome6()
{
initFont();
return iconFontAwesome6->getIconFont();
}
QFont IconHelper::getIconFontWeather() QFont IconHelper::getIconFontWeather()
{ {
initFont(); initFont();
@ -48,6 +63,7 @@ IconHelper *IconHelper::getIconHelper(int icon)
//没指定则自动根据不同的字体的值选择对应的类 //没指定则自动根据不同的字体的值选择对应的类
//由于部分值范围冲突所以可以指定索引来取 //由于部分值范围冲突所以可以指定索引来取
//fontawesome 0xf000-0xf2e0 //fontawesome 0xf000-0xf2e0
//fontawesome6 0xe000-0xe33d 0xf000-0xf8ff
//iconfont 0xe501-0xe793 0xe8d5-0xea5d //iconfont 0xe501-0xe793 0xe8d5-0xea5d
//weather 0xe900-0xe9cf //weather 0xe900-0xe9cf
@ -61,6 +77,8 @@ IconHelper *IconHelper::getIconHelper(int icon)
} else if (iconFontIndex == 1) { } else if (iconFontIndex == 1) {
iconHelper = iconFontAwesome; iconHelper = iconFontAwesome;
} else if (iconFontIndex == 2) { } else if (iconFontIndex == 2) {
iconHelper = iconFontAwesome6;
} else if (iconFontIndex == 3) {
iconHelper = iconFontWeather; iconHelper = iconFontWeather;
} }
@ -115,7 +133,7 @@ IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName)) { if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

View File

@ -31,6 +31,18 @@ class IconHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
private:
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//FontAwesome6图形字体类
static IconHelper *iconFontAwesome6;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
public: public:
//样式颜色结构体 //样式颜色结构体
struct StyleColor { struct StyleColor {
@ -90,21 +102,16 @@ public:
} }
}; };
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
//初始化图形字体 //初始化图形字体
static void initFont(); static void initFont();
//设置引用图形字体文件索引
static void setIconFontIndex(int index);
//获取图形字体 //获取图形字体
static QFont getIconFontAliBaBa(); static QFont getIconFontAliBaBa();
static QFont getIconFontAwesome(); static QFont getIconFontAwesome();
static QFont getIconFontAwesome6();
static QFont getIconFontWeather(); static QFont getIconFontWeather();
//根据值获取图形字体类 //根据值获取图形字体类

View File

@ -47,5 +47,21 @@ void Widget::on_btnOk_clicked()
} }
//计算下来3年期定期存款30年总金额翻2番到最初本金3倍 100W本金3年期自动续期30年=321W //计算下来3年期定期存款30年总金额翻2番到最初本金3倍 100W本金3年期自动续期30年=321W
ui->txtMoneyAll->setText(QString::number(moneyAll)); QString value = QString::number(moneyAll);
ui->txtMoneyAll->setText(value);
//拷贝到其他地方
if (ui->rbtn1->isChecked()) {
ui->txtValue1->setText(value);
} else {
ui->txtValue2->setText(value);
}
//计算两种存款方式的差额 比如1年期存3年和3年期存3年
QString value1 = ui->txtValue1->text().trimmed();
QString value2 = ui->txtValue2->text().trimmed();
if (!value1.isEmpty() && !value2.isEmpty()) {
int value = qAbs(value1.toInt() - value2.toInt());
ui->txtValue->setText(QString::number(value));
}
} }

View File

@ -13,138 +13,228 @@
<property name="windowTitle"> <property name="windowTitle">
<string>存款计算器</string> <string>存款计算器</string>
</property> </property>
<widget class="QWidget" name="layoutWidget"> <layout class="QGridLayout" name="gridLayout_2">
<property name="geometry"> <item row="0" column="0">
<rect> <widget class="QWidget" name="widget" native="true">
<x>10</x> <property name="maximumSize">
<y>10</y> <size>
<width>431</width> <width>600</width>
<height>86</height> <height>16777215</height>
</rect> </size>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="1" column="2"> <property name="leftMargin">
<widget class="QLabel" name="labYears"> <number>0</number>
<property name="text">
<string>年限</string>
</property> </property>
</widget> <property name="topMargin">
</item> <number>0</number>
<item row="0" column="0">
<widget class="QLabel" name="labMoneyCurrent">
<property name="text">
<string>本金</string>
</property> </property>
</widget> <property name="rightMargin">
</item> <number>0</number>
<item row="0" column="3">
<widget class="QLineEdit" name="txtRate">
<property name="text">
<string>0.04125</string>
</property> </property>
</widget> <property name="bottomMargin">
</item> <number>0</number>
<item row="0" column="1">
<widget class="QLineEdit" name="txtMoneyCurrent">
<property name="text">
<string>1000000</string>
</property> </property>
</widget> <item row="2" column="3">
</item> <widget class="QLineEdit" name="txtMoneyAll"/>
<item row="0" column="2">
<widget class="QLabel" name="labRate">
<property name="text">
<string>利率</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labYear">
<property name="text">
<string>期限</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labType">
<property name="text">
<string>方式</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QComboBox" name="cboxType">
<property name="currentIndex">
<number>1</number>
</property>
<item>
<property name="text">
<string>单利</string>
</property>
</item> </item>
<item> <item row="1" column="0">
<property name="text"> <widget class="QLabel" name="labYear">
<string>复利</string> <property name="text">
</property> <string>期限</string>
</property>
</widget>
</item> </item>
</widget> <item row="0" column="2">
</item> <widget class="QLabel" name="labRate">
<item row="1" column="1"> <property name="text">
<widget class="QComboBox" name="cboxYear"> <string>利率</string>
<property name="currentIndex"> </property>
<number>1</number> </widget>
</property>
<item>
<property name="text">
<string>1年</string>
</property>
</item> </item>
<item> <item row="2" column="1">
<property name="text"> <widget class="QComboBox" name="cboxType">
<string>3年</string> <property name="currentIndex">
</property> <number>1</number>
</property>
<item>
<property name="text">
<string>单利</string>
</property>
</item>
<item>
<property name="text">
<string>复利</string>
</property>
</item>
</widget>
</item> </item>
<item> <item row="2" column="6">
<property name="text"> <widget class="QLineEdit" name="txtValue"/>
<string>5年</string>
</property>
</item> </item>
</widget> <item row="0" column="1">
</item> <widget class="QLineEdit" name="txtMoneyCurrent">
<item row="1" column="3"> <property name="text">
<widget class="QLineEdit" name="txtYears"> <string>1000000</string>
<property name="text"> </property>
<string>30</string> </widget>
</property> </item>
</widget> <item row="0" column="4" rowspan="3">
</item> <widget class="QPushButton" name="btnOk">
<item row="2" column="3"> <property name="sizePolicy">
<widget class="QLineEdit" name="txtMoneyAll"/> <sizepolicy hsizetype="Minimum" vsizetype="Expanding">
</item> <horstretch>0</horstretch>
<item row="2" column="2"> <verstretch>0</verstretch>
<widget class="QLabel" name="labMoneyAll"> </sizepolicy>
<property name="text"> </property>
<string>总计</string> <property name="text">
</property> <string>计算</string>
</widget> </property>
</item> </widget>
<item row="0" column="4" rowspan="3"> </item>
<widget class="QPushButton" name="btnOk"> <item row="0" column="6">
<property name="sizePolicy"> <widget class="QLineEdit" name="txtValue1"/>
<sizepolicy hsizetype="Minimum" vsizetype="Expanding"> </item>
<horstretch>0</horstretch> <item row="0" column="0">
<verstretch>0</verstretch> <widget class="QLabel" name="labMoneyCurrent">
</sizepolicy> <property name="text">
</property> <string>本金</string>
<property name="text"> </property>
<string>计算</string> </widget>
</property> </item>
</widget> <item row="1" column="1">
</item> <widget class="QComboBox" name="cboxYear">
</layout> <property name="currentIndex">
</widget> <number>1</number>
</property>
<item>
<property name="text">
<string>1年</string>
</property>
</item>
<item>
<property name="text">
<string>3年</string>
</property>
</item>
<item>
<property name="text">
<string>5年</string>
</property>
</item>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="labYears">
<property name="text">
<string>年限</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="labType">
<property name="text">
<string>方式</string>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QRadioButton" name="rbtn2">
<property name="text">
<string>总计2</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QLineEdit" name="txtValue2"/>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="txtRate">
<property name="text">
<string>0.04125</string>
</property>
</widget>
</item>
<item row="0" column="5">
<widget class="QRadioButton" name="rbtn1">
<property name="text">
<string>总计1</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="labMoneyAll">
<property name="text">
<string>总计</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QLabel" name="labValue">
<property name="text">
<string>总计差额</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="txtYears">
<property name="text">
<string>30</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>19</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>489</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget> </widget>
<layoutdefault spacing="6" margin="11"/> <layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>txtMoneyCurrent</tabstop>
<tabstop>txtRate</tabstop>
<tabstop>cboxYear</tabstop>
<tabstop>txtYears</tabstop>
<tabstop>cboxType</tabstop>
<tabstop>txtMoneyAll</tabstop>
<tabstop>btnOk</tabstop>
<tabstop>rbtn1</tabstop>
<tabstop>txtValue1</tabstop>
<tabstop>rbtn2</tabstop>
<tabstop>txtValue2</tabstop>
<tabstop>txtValue</tabstop>
</tabstops>
<resources/> <resources/>
<connections/> <connections/>
</ui> </ui>

View File

@ -2,6 +2,7 @@
IconHelper *IconHelper::iconFontAliBaBa = 0; IconHelper *IconHelper::iconFontAliBaBa = 0;
IconHelper *IconHelper::iconFontAwesome = 0; IconHelper *IconHelper::iconFontAwesome = 0;
IconHelper *IconHelper::iconFontAwesome6 = 0;
IconHelper *IconHelper::iconFontWeather = 0; IconHelper *IconHelper::iconFontWeather = 0;
int IconHelper::iconFontIndex = -1; int IconHelper::iconFontIndex = -1;
@ -16,12 +17,20 @@ void IconHelper::initFont()
if (iconFontAwesome == 0) { if (iconFontAwesome == 0) {
iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome"); iconFontAwesome = new IconHelper(":/font/fontawesome-webfont.ttf", "FontAwesome");
} }
if (iconFontAwesome6 == 0) {
iconFontAwesome6 = new IconHelper(":/font/fa-regular-400.ttf", "Font Awesome 6 Pro Regular");
}
if (iconFontWeather == 0) { if (iconFontWeather == 0) {
iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather"); iconFontWeather = new IconHelper(":/font/pe-icon-set-weather.ttf", "pe-icon-set-weather");
} }
} }
} }
void IconHelper::setIconFontIndex(int index)
{
iconFontIndex = index;
}
QFont IconHelper::getIconFontAliBaBa() QFont IconHelper::getIconFontAliBaBa()
{ {
initFont(); initFont();
@ -34,6 +43,12 @@ QFont IconHelper::getIconFontAwesome()
return iconFontAwesome->getIconFont(); return iconFontAwesome->getIconFont();
} }
QFont IconHelper::getIconFontAwesome6()
{
initFont();
return iconFontAwesome6->getIconFont();
}
QFont IconHelper::getIconFontWeather() QFont IconHelper::getIconFontWeather()
{ {
initFont(); initFont();
@ -48,6 +63,7 @@ IconHelper *IconHelper::getIconHelper(int icon)
//没指定则自动根据不同的字体的值选择对应的类 //没指定则自动根据不同的字体的值选择对应的类
//由于部分值范围冲突所以可以指定索引来取 //由于部分值范围冲突所以可以指定索引来取
//fontawesome 0xf000-0xf2e0 //fontawesome 0xf000-0xf2e0
//fontawesome6 0xe000-0xe33d 0xf000-0xf8ff
//iconfont 0xe501-0xe793 0xe8d5-0xea5d //iconfont 0xe501-0xe793 0xe8d5-0xea5d
//weather 0xe900-0xe9cf //weather 0xe900-0xe9cf
@ -61,6 +77,8 @@ IconHelper *IconHelper::getIconHelper(int icon)
} else if (iconFontIndex == 1) { } else if (iconFontIndex == 1) {
iconHelper = iconFontAwesome; iconHelper = iconFontAwesome;
} else if (iconFontIndex == 2) { } else if (iconFontIndex == 2) {
iconHelper = iconFontAwesome6;
} else if (iconFontIndex == 3) {
iconHelper = iconFontWeather; iconHelper = iconFontWeather;
} }
@ -115,7 +133,7 @@ IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName)) { if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

View File

@ -31,6 +31,18 @@ class IconHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
private:
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//FontAwesome6图形字体类
static IconHelper *iconFontAwesome6;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
public: public:
//样式颜色结构体 //样式颜色结构体
struct StyleColor { struct StyleColor {
@ -90,21 +102,16 @@ public:
} }
}; };
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
//初始化图形字体 //初始化图形字体
static void initFont(); static void initFont();
//设置引用图形字体文件索引
static void setIconFontIndex(int index);
//获取图形字体 //获取图形字体
static QFont getIconFontAliBaBa(); static QFont getIconFontAliBaBa();
static QFont getIconFontAwesome(); static QFont getIconFontAwesome();
static QFont getIconFontAwesome6();
static QFont getIconFontWeather(); static QFont getIconFontWeather();
//根据值获取图形字体类 //根据值获取图形字体类

Binary file not shown.

View File

@ -29,11 +29,11 @@ bool frmIconHelper::eventFilter(QObject *watched, QEvent *event)
if (lab != 0) { if (lab != 0) {
//由于有图形字体的范围值冲突需要手动切换索引 //由于有图形字体的范围值冲突需要手动切换索引
if (ui->rbtnFontAwesome6->isChecked()) { if (ui->rbtnFontAwesome6->isChecked()) {
IconHelper::iconFontIndex = 2; IconHelper::setIconFontIndex(2);
} else if (ui->rbtnFontWeather->isChecked()) { } else if (ui->rbtnFontWeather->isChecked()) {
IconHelper::iconFontIndex = 3; IconHelper::setIconFontIndex(3);
} else { } else {
IconHelper::iconFontIndex = -1; IconHelper::setIconFontIndex(-1);
} }
//对应图形字体的16进制值已经赋值给了 toolTip //对应图形字体的16进制值已经赋值给了 toolTip
@ -121,7 +121,8 @@ void frmIconHelper::initPanel()
int start = 0xf000; int start = 0xf000;
int end = 0xf2e0; int end = 0xf2e0;
QFont iconFont = IconHelper::getIconFontAwesome(); QFont iconFont = IconHelper::getIconFontAwesome();
IconHelper::iconFontIndex = -1; IconHelper::setIconFontIndex(-1);
if (ui->rbtnFontAliBaBa->isChecked()) { if (ui->rbtnFontAliBaBa->isChecked()) {
start = 0xe500; start = 0xe500;
end = 0xea5d; end = 0xea5d;
@ -130,12 +131,12 @@ void frmIconHelper::initPanel()
start = 0xe000; start = 0xe000;
end = 0xf8ff; end = 0xf8ff;
iconFont = IconHelper::getIconFontAwesome6(); iconFont = IconHelper::getIconFontAwesome6();
IconHelper::iconFontIndex = 2; IconHelper::setIconFontIndex(2);
} else if (ui->rbtnFontWeather->isChecked()) { } else if (ui->rbtnFontWeather->isChecked()) {
start = 0xe900; start = 0xe900;
end = 0xe9cf; end = 0xe9cf;
iconFont = IconHelper::getIconFontWeather(); iconFont = IconHelper::getIconFontWeather();
IconHelper::iconFontIndex = 3; IconHelper::setIconFontIndex(3);
} }
//设置字体大小 //设置字体大小

View File

@ -26,6 +26,11 @@ void IconHelper::initFont()
} }
} }
void IconHelper::setIconFontIndex(int index)
{
iconFontIndex = index;
}
QFont IconHelper::getIconFontAliBaBa() QFont IconHelper::getIconFontAliBaBa()
{ {
initFont(); initFont();
@ -128,7 +133,7 @@ IconHelper::IconHelper(const QString &fontFile, const QString &fontName, QObject
{ {
//判断图形字体是否存在,不存在则加入 //判断图形字体是否存在,不存在则加入
QFontDatabase fontDb; QFontDatabase fontDb;
if (!fontDb.families().contains(fontName)) { if (!fontDb.families().contains(fontName) && QFile(fontFile).exists()) {
int fontId = fontDb.addApplicationFont(fontFile); int fontId = fontDb.addApplicationFont(fontFile);
QStringList listName = fontDb.applicationFontFamilies(fontId); QStringList listName = fontDb.applicationFontFamilies(fontId);
if (listName.count() == 0) { if (listName.count() == 0) {

View File

@ -31,6 +31,18 @@ class IconHelper : public QObject
{ {
Q_OBJECT Q_OBJECT
private:
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//FontAwesome6图形字体类
static IconHelper *iconFontAwesome6;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
public: public:
//样式颜色结构体 //样式颜色结构体
struct StyleColor { struct StyleColor {
@ -90,19 +102,11 @@ public:
} }
}; };
//阿里巴巴图形字体类
static IconHelper *iconFontAliBaBa;
//FontAwesome图形字体类
static IconHelper *iconFontAwesome;
//FontAwesome6图形字体类
static IconHelper *iconFontAwesome6;
//天气图形字体类
static IconHelper *iconFontWeather;
//图形字体索引
static int iconFontIndex;
//初始化图形字体 //初始化图形字体
static void initFont(); static void initFont();
//设置引用图形字体文件索引
static void setIconFontIndex(int index);
//获取图形字体 //获取图形字体
static QFont getIconFontAliBaBa(); static QFont getIconFontAliBaBa();

View File

@ -3,5 +3,6 @@
<file>font/fontawesome-webfont.ttf</file> <file>font/fontawesome-webfont.ttf</file>
<file>font/iconfont.ttf</file> <file>font/iconfont.ttf</file>
<file>font/pe-icon-set-weather.ttf</file> <file>font/pe-icon-set-weather.ttf</file>
<file>font/fa-regular-400.ttf</file>
</qresource> </qresource>
</RCC> </RCC>