HMI-26-【HUD】HUD重新编写

简介: 基于Qt的汽车仪表模拟

image.png

点此链接查看视频

image.png

在前面GC9项目之前其实单独写过一个HUD,这里就直接把原来的资源弄过,按照现在的想的思路重新搞一次。

HUD北京为透明,这样可以感觉是真的投在玻璃上。HUD上面目前引出的接口如下

/**
     * @brief fastStart
     * 快速启动
     */
    void fastStart();
    /**
     * @brief selfInspection
     * 自检程序
     */
    void selfInspection();
    /**
     * @brief powerUp
     * HUD上电操作
     */
    void powerUp();
    /**
     * @brief powerOff
     * HUD断电操作
     */
    void powerOff();
    /**
     * @brief setLaneKeeping
     * 设置车道保持
     */
    void setLaneKeeping(LaneKeep temp = m_LaneKeep_No);
    /**
     * @brief setCruiseControl
     * @param temp
     * 设置定速巡航
     */
    void setCruiseControl(bool temp);
    /**
     * @brief setSelfAdaptiveCruiseControl
     * @param temp
     * 设置自适应巡航
     */
    void setSelfAdaptiveCruiseControl(bool temp);
    /**
     * @brief setSelfAdaptiveCruiseControlDistance
     * @param temp
     * 设置距离
     */
    void setSelfAdaptiveCruiseControlDistance(int temp);
    /**
     * @brief setSelfAdaptiveCruiseControlModel
     * @param temp
     * 设置自适应巡航模式
     */
    void setSelfAdaptiveCruiseControlModel(SelfAdaptiveCruiseControlModel temp);
    /**
     * @brief setCarSpeed
     * @param temp
     * 设置车速
     */
    void setCarSpeed(int temp);
    /**
     * @brief setTurnLight
     * @param temp
     * 设置转向灯
     */
    void setTurnLight(int temp);
    /**
     * @brief setDirection
     * @param temp
     * 设置导航方向
     */
    void setDirection(Direction temp);
    /**
     * @brief setDirectionDistance
     * @param temp
     * 设置距离
     */
    void setDirectionDistance(int temp = 150);

显示速度的数字仪表部分实现代码如下

#ifndef HUD_NUMBER_H
#define HUD_NUMBER_H
#include <QWidget>
#include <QThread>
class HUDNumberThread :  public QThread
{
    Q_OBJECT
public:
    /**
     * @brief run
     * 重载线程函数
     */
    virtual void run();
signals:
     void signalTimeOut();
};
namespace Ui {
class HUD_Number;
}
class HUD_Number : public QWidget
{
    Q_OBJECT
public:
    explicit HUD_Number(QWidget *parent = nullptr);
    ~HUD_Number();
    /**
     * @brief set_Number
     * @param number
     * 设置车速
     */
    void setNumber(int number = 888);
    void selfInspection();
private:
    Ui::HUD_Number *ui;
    HUDNumberThread *m_hudNumber = nullptr;
};
#endif // HUD_NUMBER_H
#include "hud_number.h"
#include "ui_hud_number.h"
HUD_Number::HUD_Number(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HUD_Number)
{
    ui->setupUi(this);
}
HUD_Number::~HUD_Number()
{
    delete ui;
}
void HUD_Number::setNumber(int number)
{
    if(number<10)
    {
        ui->label_N_B->hide();
        ui->label_N_S->hide();
        ui->label_N_G->show();
        ui->label_N_G->setGeometry(104,0,104,147);
        ui->label_N_KM->move(ui->label_N_G->x()+6,154);
        switch (number)
        {
        case 0:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)");
            break;
        case 1:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)");
            break;
        case 2:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)");
            break;
        case 3:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)");
            break;
        case 4:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)");
            break;
        case 5:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)");
            break;
        case 6:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)");
            break;
        case 7:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)");
            break;
        case 8:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)");
            break;
        case 9:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)");
            break;
        default:
            break;
        }
    }
    else if(number>=10 && number <100)
    {
        ui->label_N_B->hide();
        ui->label_N_S->show();
        ui->label_N_G->show();
        ui->label_N_S->setGeometry(52,0,104,147);
        ui->label_N_G->setGeometry(156,0,104,147);
        ui->label_N_KM->move(ui->label_N_G->x()+6,154);
        switch (number%10)
        {
        case 0:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)");
            break;
        case 1:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)");
            break;
        case 2:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)");
            break;
        case 3:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)");
            break;
        case 4:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)");
            break;
        case 5:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)");
            break;
        case 6:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)");
            break;
        case 7:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)");
            break;
        case 8:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)");
            break;
        case 9:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)");
            break;
        default:
            break;
        }
        switch (number/10)
        {
        case 0:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)");
            break;
        case 1:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)");
            break;
        case 2:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)");
            break;
        case 3:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)");
            break;
        case 4:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)");
            break;
        case 5:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)");
            break;
        case 6:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)");
            break;
        case 7:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)");
            break;
        case 8:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)");
            break;
        case 9:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)");
            break;
        default:
            break;
        }
    }
    else if(number>=100 && number < 1000)
    {
        ui->label_N_B->show();
        ui->label_N_S->show();
        ui->label_N_G->show();
        ui->label_N_B->setGeometry(0,0,104,147);
        ui->label_N_S->setGeometry(104,0,104,147);
        ui->label_N_G->setGeometry(208,0,104,147);
        ui->label_N_KM->move(ui->label_N_G->x()+6,154);
        switch (number%10)
        {
        case 0:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)");
            break;
        case 1:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)");
            break;
        case 2:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)");
            break;
        case 3:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)");
            break;
        case 4:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)");
            break;
        case 5:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)");
            break;
        case 6:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)");
            break;
        case 7:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)");
            break;
        case 8:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)");
            break;
        case 9:
            ui->label_N_G->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)");
            break;
        default:
            break;
        }
        switch (number/10%10)
        {
        case 0:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)");
            break;
        case 1:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)");
            break;
        case 2:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)");
            break;
        case 3:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)");
            break;
        case 4:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)");
            break;
        case 5:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)");
            break;
        case 6:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)");
            break;
        case 7:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)");
            break;
        case 8:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)");
            break;
        case 9:
            ui->label_N_S->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)");
            break;
        default:
            break;
        }
        switch (number/100)
        {
        case 0:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/0.png)");
            break;
        case 1:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/1.png)");
            break;
        case 2:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/2.png)");
            break;
        case 3:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/3.png)");
            break;
        case 4:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/4.png)");
            break;
        case 5:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/5.png)");
            break;
        case 6:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/6.png)");
            break;
        case 7:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/7.png)");
            break;
        case 8:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/8.png)");
            break;
        case 9:
            ui->label_N_B->setStyleSheet("border-image:url(:/Number/Resources/Hud/Number/9.png)");
            break;
        default:
            break;
        }
    }
    else
    {
    }
}
void HUD_Number::selfInspection()
{
    setNumber();
    if(!m_hudNumber)
    {
        m_hudNumber = new HUDNumberThread();
        connect(m_hudNumber,&HUDNumberThread::signalTimeOut,this,[=](){setNumber(0);});
        m_hudNumber->start();
    }
}
void HUDNumberThread::run()
{
    msleep(3000);
    emit signalTimeOut();
}

转向灯实现代码如下

#ifndef HUD_TURNLIGHT_H
#define HUD_TURNLIGHT_H
#include <QWidget>
#include <QThread>
class HUDTurnLIghtThread :  public QThread
{
    Q_OBJECT
public:
    /**
     * @brief run
     * 重载线程函数
     */
    virtual void run();
signals:
     void signalTimeOut();
};
namespace Ui {
class HUD_TurnLight;
}
class HUD_TurnLight : public QWidget
{
    Q_OBJECT
public:
    explicit HUD_TurnLight(QWidget *parent = nullptr);
    ~HUD_TurnLight();
    /**
     * @brief selfInspection
     * 初始化
     */
    void selfInspection();
    /**
     * @brief setTurnLight
     * @param temp
     * 设置转向灯
     */
    void setTurnLight(int temp);
private:
    Ui::HUD_TurnLight *ui;
    HUDTurnLIghtThread *m_hudTurnLightThread = nullptr;
    QTimer *m_timerTurnLeft = nullptr;     //左转向灯定时器
    QTimer *m_timerTurnRight = nullptr;    //右转向灯定时器
};
#endif // HUD_TURNLIGHT_H
#include "hud_turnlight.h"
#include "ui_hud_turnlight.h"
#include <QTimer>
HUD_TurnLight::HUD_TurnLight(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HUD_TurnLight)
{
    ui->setupUi(this);
    ui->label_turnLIght_L->hide();
    ui->label_turnLIght_L->hide();
    m_timerTurnLeft = new QTimer(this);
    m_timerTurnRight = new QTimer(this);
    connect(m_timerTurnLeft,&QTimer::timeout,this,[=](){
        if(ui->label_turnLIght_L->isHidden())
        {
            ui->label_turnLIght_L->show();
        }
        else
        {
            ui->label_turnLIght_L->hide();
        }
    });
    connect(m_timerTurnRight,&QTimer::timeout,this,[=](){
        if(ui->label_turnLIght_L->isHidden())
        {
            ui->label_turnLIght_L->show();
        }
        else
        {
            ui->label_turnLIght_L->hide();
        }
    });
}
HUD_TurnLight::~HUD_TurnLight()
{
    delete ui;
}
void HUD_TurnLight::selfInspection()
{
    ui->label_turnLIght_L->show();
    ui->label_turnLIght_R->show();
    if(!m_hudTurnLightThread)
    {
        m_hudTurnLightThread = new HUDTurnLIghtThread();
        connect(m_hudTurnLightThread,&HUDTurnLIghtThread::signalTimeOut,this,[=](){
            ui->label_turnLIght_L->hide();
            ui->label_turnLIght_R->hide();
        });
        m_hudTurnLightThread->start();
    }
}
void HUD_TurnLight::setTurnLight(int temp)
{
    switch (temp) {
    case 0:
    {
        if(m_timerTurnRight->isActive())
        {
            m_timerTurnRight->stop();
            ui->label_turnLIght_L->hide();
        }
        m_timerTurnLeft->start(1000);
        break;
    }
    case 1:
    {
        if(m_timerTurnLeft->isActive())
        {
            m_timerTurnLeft->stop();
            ui->label_turnLIght_L->hide();
        }
        m_timerTurnRight->start(1000);
        break;
    }
    case 2:
    {
        m_timerTurnLeft->start(1000);
        m_timerTurnRight->start(1000);
        break;
    }
    case 3:
    {
        if(m_timerTurnLeft->isActive())
        {
            m_timerTurnLeft->stop();
            ui->label_turnLIght_L->hide();
        }
        if(m_timerTurnRight->isActive())
        {
            m_timerTurnRight->stop();
            ui->label_turnLIght_R->hide();
        }
        break;
    }
    }
}
void HUDTurnLIghtThread::run()
{
    msleep(3000);
    emit signalTimeOut();
}

导航实现代码如下

#ifndef HUD_DIRECTION_H
#define HUD_DIRECTION_H
#include <QWidget>
#include <QThread>
enum Direction{
    m_straight,
    m_rightUp,
    m_right,
    m_rightDown,
    m_turnaround,
    m_leftDown,
    m_left,
    m_leftUp
};
class HUDDirectionThread :  public QThread
{
    Q_OBJECT
public:
    /**
     * @brief run
     * 重载线程函数
     */
    virtual void run();
signals:
     void signalTimeOut();
};
namespace Ui {
class HUD_Direction;
}
class HUD_Direction : public QWidget
{
    Q_OBJECT
public:
    explicit HUD_Direction(QWidget *parent = nullptr);
    ~HUD_Direction();
    /**
     * @brief setDirection
     * @param temp
     * 设置导航方向
     */
    void setDirection(Direction temp);
    /**
     * @brief setDirectionDistance
     * @param temp
     * 设置距离
     */
    void setDirectionDistance(int temp = 150);
    void selfInspection();
private:
    Ui::HUD_Direction *ui;
    HUDDirectionThread *m_hudDirectionThrerad = nullptr;
};
#endif // HUD_DIRECTION_H
#include "hud_direction.h"
#include "ui_hud_direction.h"
HUD_Direction::HUD_Direction(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HUD_Direction)
{
    ui->setupUi(this);
    ui->label_up->hide();
    ui->label_left->hide();
    ui->label_leftUp->hide();
    ui->label_right->hide();
    ui->label_line_1->hide();
    ui->label_line_2->hide();
    ui->label_line_3->hide();
    ui->label_rightUp->hide();
    ui->label_leftDown->hide();
    ui->label_lineBase->hide();
    ui->label_rightDown->hide();
    ui->label_turnraound->hide();
    ui->label_pointer->hide();
    ui->label_base->hide();
//    setDirection(m_rightUp);
//    setDirectionDistance(110);
}
HUD_Direction::~HUD_Direction()
{
    delete ui;
}
void HUD_Direction::setDirection(Direction temp)
{
    switch (temp) {
    case m_straight:
    {
        ui->label_up->show();
        ui->label_left->hide();
        ui->label_leftUp->hide();
        ui->label_right->hide();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->hide();
        ui->label_leftDown->hide();
        ui->label_lineBase->hide();
        ui->label_rightDown->hide();
        ui->label_turnraound->hide();
        ui->label_pointer->show();
        ui->label_base->show();
        break;
    }
    case m_rightUp:
    {
        ui->label_up->hide();
        ui->label_left->hide();
        ui->label_leftUp->hide();
        ui->label_right->hide();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->show();
        ui->label_leftDown->hide();
        ui->label_lineBase->hide();
        ui->label_rightDown->hide();
        ui->label_turnraound->hide();
        ui->label_pointer->show();
        ui->label_base->show();
        break;
    }
    case m_right:
    {
        ui->label_up->hide();
        ui->label_left->hide();
        ui->label_leftUp->hide();
        ui->label_right->show();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->hide();
        ui->label_leftDown->hide();
        ui->label_lineBase->hide();
        ui->label_rightDown->hide();
        ui->label_turnraound->hide();
        ui->label_pointer->show();
        ui->label_base->show();
        break;
    }
    case m_rightDown:
    {
        ui->label_up->hide();
        ui->label_left->hide();
        ui->label_leftUp->hide();
        ui->label_right->hide();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->hide();
        ui->label_leftDown->hide();
        ui->label_lineBase->hide();
        ui->label_rightDown->show();
        ui->label_turnraound->hide();
        ui->label_pointer->show();
        ui->label_base->show();
        break;
    }
    case m_turnaround:
    {
        ui->label_up->hide();
        ui->label_left->hide();
        ui->label_leftUp->hide();
        ui->label_right->hide();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->hide();
        ui->label_leftDown->hide();
        ui->label_lineBase->hide();
        ui->label_rightDown->hide();
        ui->label_turnraound->show();
        ui->label_base->hide();
        ui->label_pointer->hide();
        break;
    }
    case m_leftDown:
    {
        ui->label_up->hide();
        ui->label_left->hide();
        ui->label_leftUp->hide();
        ui->label_right->hide();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->hide();
        ui->label_leftDown->show();
        ui->label_lineBase->hide();
        ui->label_rightDown->hide();
        ui->label_turnraound->hide();
        ui->label_pointer->show();
        ui->label_base->show();
        break;
    }
    case m_left:
    {
        ui->label_up->hide();
        ui->label_left->show();
        ui->label_leftUp->hide();
        ui->label_right->hide();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->hide();
        ui->label_leftDown->hide();
        ui->label_lineBase->hide();
        ui->label_rightDown->hide();
        ui->label_turnraound->hide();
        ui->label_pointer->show();
        ui->label_base->show();
        break;
    }
    case m_leftUp:
    {
        ui->label_up->hide();
        ui->label_left->hide();
        ui->label_leftUp->show();
        ui->label_right->hide();
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_rightUp->hide();
        ui->label_leftDown->hide();
        ui->label_lineBase->hide();
        ui->label_rightDown->hide();
        ui->label_turnraound->hide();
        ui->label_pointer->show();
        ui->label_base->show();
        break;
    }
    }
}
void HUD_Direction::setDirectionDistance(int temp)
{
    if(temp>100 && temp <= 150)
    {
        ui->label_line_1->show();
        ui->label_line_2->show();
        ui->label_line_3->show();
        ui->label_lineBase->show();
    }
    else if(temp <= 100 && temp >50)
    {
        ui->label_line_1->show();
        ui->label_line_2->show();
        ui->label_line_3->hide();
        ui->label_lineBase->show();
    }
    else if(temp <= 50 && temp >0)
    {
        ui->label_line_1->show();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_lineBase->show();
    }
    else if(temp<= 0)
    {
        ui->label_line_1->hide();
        ui->label_line_2->hide();
        ui->label_line_3->hide();
        ui->label_lineBase->hide();
    }
}
void HUD_Direction::selfInspection()
{
    ui->label_up->show();
    ui->label_left->show();
    ui->label_leftUp->show();
    ui->label_right->show();
    ui->label_line_1->show();
    ui->label_line_2->show();
    ui->label_line_3->show();
    ui->label_rightUp->show();
    ui->label_leftDown->show();
    ui->label_lineBase->show();
    ui->label_rightDown->show();
    ui->label_turnraound->show();
    ui->label_pointer->show();
    ui->label_base->hide();
    if(!m_hudDirectionThrerad)
    {
        m_hudDirectionThrerad = new HUDDirectionThread();
        connect(m_hudDirectionThrerad,&HUDDirectionThread::signalTimeOut,this,[=](){
            ui->label_up->hide();
            ui->label_left->hide();
            ui->label_leftUp->hide();
            ui->label_right->hide();
            ui->label_line_1->hide();
            ui->label_line_2->hide();
            ui->label_line_3->hide();
            ui->label_rightUp->hide();
            ui->label_leftDown->hide();
            ui->label_lineBase->hide();
            ui->label_rightDown->hide();
            ui->label_turnraound->hide();
            ui->label_pointer->hide();
            ui->label_base->hide();
        });
        m_hudDirectionThrerad->start();
    }
}
void HUDDirectionThread::run()
{
    msleep(3000);
    emit signalTimeOut();
}

巡航代码如下

#ifndef HUD_CRUISE_H
#define HUD_CRUISE_H
#include <QWidget>
#include <QThread>
enum LaneKeep
{
    m_LaneKeep_No,
    m_LaneKeep_Left,
    m_LaneKeep_Right,
    m_LaneKeep_Double
};
enum SelfAdaptiveCruiseControlModel
{
    m_SelfAdaptiveCruiseControlModel_Near,
    m_SelfAdaptiveCruiseControlModel_Normal,
    m_SelfAdaptiveCruiseControlModel_Far
};
class HUDCruiseThread :  public QThread
{
    Q_OBJECT
public:
    /**
     * @brief run
     * 重载线程函数
     */
    virtual void run();
signals:
     void signalTimeOut();
};
namespace Ui {
class HUD_Cruise;
}
class HUD_Cruise : public QWidget
{
    Q_OBJECT
public:
    explicit HUD_Cruise(QWidget *parent = nullptr);
    ~HUD_Cruise();
    /**
     * @brief selfInspection
     * 自检函数
     */
    void selfInspection();
    /**
     * @brief setLaneKeeping
     * 设置车道保持
     */
    void setLaneKeeping(LaneKeep temp = m_LaneKeep_No);
    /**
     * @brief setCruiseControl
     * @param temp
     * 设置定速巡航
     */
    void setCruiseControl(bool temp);
    /**
     * @brief setSelfAdaptiveCruiseControl
     * @param temp
     * 设置自适应巡航
     */
    void setSelfAdaptiveCruiseControl(bool temp);
    /**
     * @brief setSelfAdaptiveCruiseControlDistance
     * @param temp
     * 设置距离
     */
    void setSelfAdaptiveCruiseControlDistance(int temp);
    /**
     * @brief setSelfAdaptiveCruiseControlModel
     * @param temp
     * 设置自适应巡航模式
     */
    void setSelfAdaptiveCruiseControlModel(SelfAdaptiveCruiseControlModel temp);
private:
    Ui::HUD_Cruise *ui;
    HUDCruiseThread *m_hudCruise = nullptr;
    int m_selfAdaptiveCruiseControl = 0;
};
#endif // HUD_CRUISE_H
#include "hud_cruise.h"
#include "ui_hud_cruise.h"
HUD_Cruise::HUD_Cruise(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::HUD_Cruise)
{
    ui->setupUi(this);
    ui->label_car->hide();
    ui->label_sel_1->hide();
    ui->label_sel_2->hide();
    ui->label_sel_3->hide();
    ui->label_speed->hide();
    ui->label_line_L->hide();
    ui->label_line_R->hide();
}
HUD_Cruise::~HUD_Cruise()
{
    delete ui;
}
void HUD_Cruise::selfInspection()
{
    ui->label_car->show();
    ui->label_sel_1->show();
    ui->label_sel_2->show();
    ui->label_sel_3->show();
    ui->label_speed->show();
    ui->label_line_L->show();
    ui->label_line_R->show();
    if(!m_hudCruise)
    {
        m_hudCruise = new HUDCruiseThread();
        connect(m_hudCruise,&HUDCruiseThread::signalTimeOut,this,[=](){
            ui->label_car->hide();
            ui->label_sel_1->hide();
            ui->label_sel_2->hide();
            ui->label_sel_3->hide();
            ui->label_speed->hide();
            ui->label_line_L->hide();
            ui->label_line_R->hide();
        });
        m_hudCruise->start();
    }
}
void HUD_Cruise::setLaneKeeping(LaneKeep temp)
{
    switch (temp){
    case m_LaneKeep_No:
    {
        ui->label_line_L->hide();
        ui->label_line_R->hide();
        break;
    }
    case m_LaneKeep_Left:
    {
        ui->label_line_L->show();
        ui->label_line_R->hide();
        break;
    }
    case m_LaneKeep_Right:
    {
        ui->label_line_L->hide();
        ui->label_line_R->show();
        break;
    }
    case m_LaneKeep_Double:
    {
        ui->label_line_L->show();
        ui->label_line_R->show();
        break;
    }
    }
}
void HUD_Cruise::setCruiseControl(bool temp)
{
    if(temp)
    {
        ui->label_speed->show();
    }
    else
    {
        ui->label_speed->hide();
    }
}
void HUD_Cruise::setSelfAdaptiveCruiseControl(bool temp)
{
    if(temp)
    {
        ui->label_car->show();
    }
    else
    {
        ui->label_car->hide();
    }
}
void HUD_Cruise::setSelfAdaptiveCruiseControlDistance(int temp)
{
    switch (m_selfAdaptiveCruiseControl)
    {
    case m_SelfAdaptiveCruiseControlModel_Near:
    {
        if(temp>0 && temp <= 10)
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->hide();
            ui->label_sel_1->show();
        }
        else if(temp>10 && temp <= 30)
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->show();
            ui->label_sel_1->show();
        }
        else if(temp>30 && temp <= 200)
        {
            ui->label_sel_3->show();
            ui->label_sel_2->show();
            ui->label_sel_1->show();
        }
        else
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->hide();
            ui->label_sel_1->hide();
        }
        break;
    }
    case m_SelfAdaptiveCruiseControlModel_Normal:
    {
        if(temp>0 && temp <= 10)
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->hide();
            ui->label_sel_1->show();
        }
        else if(temp>10 && temp <= 30)
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->show();
            ui->label_sel_1->show();
        }
        else if(temp>30 && temp <= 200)
        {
            ui->label_sel_3->show();
            ui->label_sel_2->show();
            ui->label_sel_1->show();
        }
        else
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->hide();
            ui->label_sel_1->hide();
        }
        break;
    }
    case m_SelfAdaptiveCruiseControlModel_Far:
    {
        if(temp>0 && temp <= 10)
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->hide();
            ui->label_sel_1->show();
        }
        else if(temp>10 && temp <= 30)
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->show();
            ui->label_sel_1->show();
        }
        else if(temp>30 && temp <= 200)
        {
            ui->label_sel_3->show();
            ui->label_sel_2->show();
            ui->label_sel_1->show();
        }
        else
        {
            ui->label_sel_3->hide();
            ui->label_sel_2->hide();
            ui->label_sel_1->hide();
        }
        break;
    }
    }
}
void HUD_Cruise::setSelfAdaptiveCruiseControlModel(SelfAdaptiveCruiseControlModel temp)
{
    m_selfAdaptiveCruiseControl = temp;
}
void HUDCruiseThread::run()
{
    msleep(3000);
    emit signalTimeOut();
}

以上就是目前HUD的实现代码

目录
相关文章
HMI-31-【运动模式】解决音乐模块图片显示问题
上一篇中,我们基本实现了音乐模块的布局显示,但是留了个小尾巴,就是图片显示,这个模块中,图片不是方正的,而是有透视的,但是呢,Qt的图像显示显示,我还没有研究那么深入,所以目前只能是像,但是肯定不是真真的透视。我是利用遮罩来实现的,其实还是平面的图片,仅仅是用了一个透视的图片模版来覆盖一下。
HMI-31-【运动模式】解决音乐模块图片显示问题
|
前端开发
Avalonia 实现动态托盘
Avalonia 实现动态托盘
241 0
Qt 汽车仪表再次编写,Widget,仪表显示,绘制界面
感谢某网友提供UI让我练练手,上目前的效果
187 0
Qt 汽车仪表再次编写,Widget,仪表显示,绘制界面
|
算法
Qt [GC9-18]:液晶仪表素材准备及转速表和速度表实现 Qlabel绘制图形
Qt [GC9-18]:液晶仪表素材准备及转速表和速度表实现 Qlabel绘制图形
249 0
Qt [GC9-18]:液晶仪表素材准备及转速表和速度表实现 Qlabel绘制图形
|
程序员 开发工具 C语言
Qt编写自定义控件43-自绘电池
一、前言 到了9102年了,现在智能手机不要太流行,满大街都是,甚至连爷爷奶奶级别的人都会用智能手机,本次要写的控件就是智能手机中的电池电量表示控件,采用纯painter绘制,其实也可以采用贴图,我估计大部分手机上的都是采用贴图的形式,贴图有个好处就是程序员不用操心,drawimage即可,速度非常快。
1822 0
|
容器
Silverlight & Blend动画设计系列五:故事板(StoryBoards)和动画(Animations)
原文:Silverlight & Blend动画设计系列五:故事板(StoryBoards)和动画(Animations)   正如你所看到的,Blend是一个非常强大的节约时间的设计工具,在Blend下能够设计出很多满意的动画作品,或许他具体是怎么实现的,通过什么方式实现的我们还是一无所知。
948 0
|
容器
Silverlight & Blend动画设计系列二:旋转动画(RotateTransform)
原文:Silverlight & Blend动画设计系列二:旋转动画(RotateTransform)   Silverlight的基础动画包括偏移、旋转、缩放、倾斜和翻转动画,这些基础动画毫无疑问是在Silverlight中使用得最多的动画效果,其使用也是非常简单的。
1019 0