| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- #include "ch_widget.h"
- #include "ui_ch_widget.h"
- #define RunStatus "#ch_Widget{border: 2px solid #00FF00;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #00FF00; }"
- #define StopStatus "#ch_Widget{border: 2px solid #0000FF;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #0000FF; }"
- ch_Widget::ch_Widget(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::ch_Widget),
- m_pCHData(nullptr)
- {
- ui->setupUi(this);
- }
- ch_Widget::~ch_Widget()
- {
- delete ui;
- }
- void ch_Widget::setDataCHP(int nIndex, PowerInfo *pdata)
- {
- if(pdata)
- {
- m_nIndex=nIndex;
- m_pCHData=pdata;
- UpdateData();
- }
- }
- void ch_Widget::UpdateData()
- {
- if(m_pCHData)
- {
- ui->label_CH->setText("CH"+QString::number(m_nIndex));
- ui->label_V->setText(QString::number(m_pCHData->voltage, 'f', 2));
- ui->label_I->setText(QString::number(m_pCHData->current, 'f', 2));
- ui->label_P->setText(QString::number(m_pCHData->power,'f', 2));
- ui->label_W->setText(QString::number(m_pCHData->consumption, 'f', 2));
- if(m_pCHData->status!=nStatus)
- {
- nStatus=m_pCHData->status;
- if(nStatus==1)
- {
- this->setStyleSheet(RunStatus);
- }else
- {
- this->setStyleSheet(StopStatus);
- }
- }
- }
- }
- bool ch_Widget::event(QEvent *event)
- {
- if (event->type() == QEvent::TouchBegin ||
- event->type() == QEvent::TouchUpdate ||
- event->type() == QEvent::TouchEnd) {
- // 不处理触摸事件,交给父级(QScrollArea 的视口)处理
- return false;
- }
- return QWidget::event(event);
- }
|