先贴上效果图,注意,没有写逻辑,所以这些都是乱动的
这里线主要说一下中间显示速度的显示制作的方式,在这里,自己专门写了一个数字的仪表
考虑的一般的汽车是没有办法把瞬时速度提升到四位数的,所以我这里就放了三位数,完了根据实时数据,更新这三个label的资源文件,在这个新的类中,只有一个函数,那就是设置数字
void set_number(int num = 0);
下面是实现方法,这个方法应该还可以优化,不过懒得优化了,先把功能堆出来。
void Number_1::set_number(int num) { int temp1 = num; int temp2 = num; switch (num%10) { case 0: ui->label_3->setStyleSheet("border-image:url(:/source/number/0.png)"); break; case 1: ui->label_3->setStyleSheet("border-image:url(:/source/number/1.png)"); break; case 2: ui->label_3->setStyleSheet("border-image:url(:/source/number/2.png)"); break; case 3: ui->label_3->setStyleSheet("border-image:url(:/source/number/3.png)"); break; case 4: ui->label_3->setStyleSheet("border-image:url(:/source/number/4.png)"); break; case 5: ui->label_3->setStyleSheet("border-image:url(:/source/number/5.png)"); break; case 6: ui->label_3->setStyleSheet("border-image:url(:/source/number/6.png)"); break; case 7: ui->label_3->setStyleSheet("border-image:url(:/source/number/7.png)"); break; case 8: ui->label_3->setStyleSheet("border-image:url(:/source/number/8.png)"); break; case 9: ui->label_3->setStyleSheet("border-image:url(:/source/number/9.png)"); break; default: break; } switch (temp1/10) { case 0: ui->label_2->setStyleSheet("border-image:url(:/source/number/0.png)"); break; case 1: ui->label_2->setStyleSheet("border-image:url(:/source/number/1.png)"); break; case 2: ui->label_2->setStyleSheet("border-image:url(:/source/number/2.png)"); break; case 3: ui->label_2->setStyleSheet("border-image:url(:/source/number/3.png)"); break; case 4: ui->label_2->setStyleSheet("border-image:url(:/source/number/4.png)"); break; case 5: ui->label_2->setStyleSheet("border-image:url(:/source/number/5.png)"); break; case 6: ui->label_2->setStyleSheet("border-image:url(:/source/number/6.png)"); break; case 7: ui->label_2->setStyleSheet("border-image:url(:/source/number/7.png)"); break; case 8: ui->label_2->setStyleSheet("border-image:url(:/source/number/8.png)"); break; case 9: ui->label_2->setStyleSheet("border-image:url(:/source/number/9.png)"); break; default: break; } switch (temp2/100) { case 0: ui->label_1->setStyleSheet("border-image:url(:/source/number/0.png)"); break; case 1: ui->label_1->setStyleSheet("border-image:url(:/source/number/1.png)"); break; case 2: ui->label_1->setStyleSheet("border-image:url(:/source/number/2.png)"); break; case 3: ui->label_1->setStyleSheet("border-image:url(:/source/number/3.png)"); break; case 4: ui->label_1->setStyleSheet("border-image:url(:/source/number/4.png)"); break; case 5: ui->label_1->setStyleSheet("border-image:url(:/source/number/5.png)"); break; case 6: ui->label_1->setStyleSheet("border-image:url(:/source/number/6.png)"); break; case 7: ui->label_1->setStyleSheet("border-image:url(:/source/number/7.png)"); break; case 8: ui->label_1->setStyleSheet("border-image:url(:/source/number/8.png)"); break; case 9: ui->label_1->setStyleSheet("border-image:url(:/source/number/9.png)"); break; default: break; } if(num<10) { ui->label_3->move(64,0); ui->label_2->hide(); ui->label_1->hide(); } else if(num >=10 && num <100) { ui->label_2->show(); ui->label_1->hide(); ui->label_2->move(32,0); ui->label_3->move(96,0); } else { ui->label_1->show(); ui->label_2->show(); ui->label_1->move(0,0); ui->label_2->move(64,0); ui->label_3->move(128,0); } }
在主程序中调用如下
number_center = new Number_1(ui->widget_center); number_center->setGeometry(0,0,192,72); number_center->show();
好了,这个速度显示的界面就搞定了