程序体验地址:https://pan.baidu.com/s/1rQFZx5JIud8lWdjMHl0tpg
目前版本还没有成功把字体打包的程序中,为了更好的效果体验,请先安装文件中的两个字体
效果图如下
布局就是图中的样子,剩下的就是一步一步的把这些接口的引出去,让我的控制台可以控制。
这里方向使用了宏定义
/* * 方向宏定义 */ #define DIRECTION_N 0 #define DIRECTION_NE 1 #define DIRECTION_E 2 #define DIRECTION_SE 3 #define DIRECTION_S 4 #define DIRECTION_SW 5 #define DIRECTION_W 6 #define DIRECTION_NW 7
声明接口函数
/** * @brief setTime * @param time * 设置时间 */ void setTime(QString time = "00:00"); /** * @brief setTemperature * @param temperature * 设置温度 */ void setTemperature(QString temperature = "-0°C"); /** * @brief setDirection * @param direction * 设置方向 */ void setDirection(int direction = 0);
在构造函数中完成基本的美化和数据的初始化
Title::Title(QWidget *parent) :QWidget(parent),ui(new Ui::Title) { ui->setupUi(this); ui->label_mainback->setStyleSheet("QLabel{border-image:url(:/Comfort/Resources/MeterDisplay/Comfort/title.png);}"); ui->pushButton_direction->setStyleSheet("QPushButton{background: transparent;color: rgb(236, 228, 216);};QPushButton:hover{background: transparent;color: rgb(236, 228, 216);};QPushButton:predded{background: transparent;color: rgb(236, 228, 216);}"); ui->label_model->setText("Comfort"); setTime(); setTemperature(); setDirection(3); }
完成对应功能实现
//设置时间 void Title::setTime(QString time) { ui->label_time->setText(time); } //设置温度 void Title::setTemperature(QString temperature) { ui->label_temperature->setText(temperature); } //设置方向 void Title::setDirection(int direction) { QSize size(0,0); switch (direction) { case DIRECTION_N: { ui->pushButton_direction->setText("N"); size.scale(18,34,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/1.png")); break; } case DIRECTION_NE: { ui->pushButton_direction->setText("NE"); size.scale(29,29,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/2.png")); break; } case DIRECTION_E: { ui->pushButton_direction->setText("E"); size.scale(31,20,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/3.png")); break; } case DIRECTION_SE: { ui->pushButton_direction->setText("SE"); size.scale(29,29,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/4.png")); break; } case DIRECTION_S: { ui->pushButton_direction->setText("S"); size.scale(18,35,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/5.png")); break; } case DIRECTION_SW: { ui->pushButton_direction->setText("SW"); size.scale(31,29,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/6.png")); break; } case DIRECTION_W: { ui->pushButton_direction->setText("W"); size.scale(31,19,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/7.png")); break; } case DIRECTION_NW: { ui->pushButton_direction->setText("NW"); size.scale(29,31,Qt::IgnoreAspectRatio); ui->pushButton_direction->setIconSize(size); ui->pushButton_direction->setIcon(QIcon(":/Comfort/Resources/MeterDisplay/Comfort/TitleDirection/8.png")); break; } default: break; } }