ch_widget.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "ch_widget.h"
  2. #include "ui_ch_widget.h"
  3. #define RunStatus "#ch_Widget{border: 2px solid #00FF00;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #00FF00; }"
  4. #define StopStatus "#ch_Widget{border: 2px solid #0000FF;background-color: #FFFFFF;border-radius: 15px;}QLabel { color: #0000FF; }"
  5. ch_Widget::ch_Widget(QWidget *parent) :
  6. QWidget(parent),
  7. ui(new Ui::ch_Widget),
  8. m_pCHData(nullptr)
  9. {
  10. ui->setupUi(this);
  11. }
  12. ch_Widget::~ch_Widget()
  13. {
  14. delete ui;
  15. }
  16. void ch_Widget::setDataCHP(int nIndex, PowerInfo *pdata)
  17. {
  18. if(pdata)
  19. {
  20. m_nIndex=nIndex;
  21. m_pCHData=pdata;
  22. UpdateData();
  23. }
  24. }
  25. void ch_Widget::UpdateData()
  26. {
  27. if(m_pCHData)
  28. {
  29. ui->label_CH->setText("CH"+QString::number(m_nIndex));
  30. ui->label_V->setText(QString::number(m_pCHData->voltage, 'f', 2));
  31. ui->label_I->setText(QString::number(m_pCHData->current, 'f', 2));
  32. ui->label_P->setText(QString::number(m_pCHData->power,'f', 2));
  33. ui->label_W->setText(QString::number(m_pCHData->consumption, 'f', 2));
  34. if(m_pCHData->status!=nStatus)
  35. {
  36. nStatus=m_pCHData->status;
  37. if(nStatus==1)
  38. {
  39. this->setStyleSheet(RunStatus);
  40. }else
  41. {
  42. this->setStyleSheet(StopStatus);
  43. }
  44. }
  45. }
  46. }
  47. bool ch_Widget::event(QEvent *event)
  48. {
  49. if (event->type() == QEvent::TouchBegin ||
  50. event->type() == QEvent::TouchUpdate ||
  51. event->type() == QEvent::TouchEnd) {
  52. // 不处理触摸事件,交给父级(QScrollArea 的视口)处理
  53. return false;
  54. }
  55. return QWidget::event(event);
  56. }