程序体验地址:https://pan.baidu.com/s/1rQFZx5JIud8lWdjMHl0tpg
目前版本还没有成功把字体打包的程序中,为了更好的效果体验,请先安装文件中的两个字体
效果图如下
目前显示内容极少,实现简单
对外接口
/** * @brief setGear * @param gear * 设置档位 */ void setGear(gearState gear); /** * @brief setLim * @param lim * 设置限速信息 */ void setLim(int lim = 0); /** * @brief setMileage * @param mileage * 设置总里程数 */ void setMileage(int mileage = 0);
这里档位信息放在了单独一个控件里面了,为的是后面还有可能用到。
BottomDisplay::BottomDisplay(QWidget *parent) : QWidget(parent),ui(new Ui::BottomDisplay) { ui->setupUi(this); m_gear = new Gear(this); m_gear->setGeometry(409,8,82,82); setLim(); setMileage(); } BottomDisplay::~BottomDisplay() { delete ui; } void BottomDisplay::setGear(gearState gear) { if(m_gear) { m_gear->setGear(gear); } } void BottomDisplay::setLim(int lim) { ui->label_lim->setText(QString::number(lim,10)+" km"); } void BottomDisplay::setMileage(int mileage) { ui->label_odo->setText(QString::number(mileage,10)+" km"); }
完成接口的功能
剩下需要看下档位信息的实现部分
表示档位信息的,用了一个枚举日下
enum gearState{ m_gearP, m_gearR, m_gearN, m_gearD1, m_gearD2, m_gearD3, m_gearD4, m_gearD5, m_gearD6, m_gearD7, m_gearD8, m_gearM1, m_gearM2, m_gearM3, m_gearM4, m_gearM5, m_gearM6, m_gearM7, m_gearM8 };
档位信息对外的接口
/** * @brief setGear * @param gear * 设置档位 */ void setGear(gearState gear = m_gearP);
实现部分,毫无技术含量
void Gear::setGear(gearState gear) { switch (gear) { case m_gearP: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/P.png);}"); break; case m_gearR: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/R.png);}"); break; case m_gearN: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/N.png);}"); break; case m_gearD1: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D1.png);}"); break; case m_gearD2: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D2.png);}"); break; case m_gearD3: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D3.png);}"); break; case m_gearD4: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D4.png);}"); break; case m_gearD5: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D5.png);}"); break; case m_gearD6: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D6.png);}"); break; case m_gearD7: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D7.png);}"); break; case m_gearD8: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/D8.png);}"); break; case m_gearM1: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M1.png);}"); break; case m_gearM2: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M2.png);}"); break; case m_gearM3: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M3.png);}"); break; case m_gearM4: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M4.png);}"); break; case m_gearM5: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M5.png);}"); break; case m_gearM6: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M6.png);}"); break; case m_gearM7: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M7.png);}"); break; case m_gearM8: ui->label_gear->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/Gears/M8.png);}"); break; default: break; } }