DoubleSpinBox.cpp 816 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #include "DoubleSpinBox.h"
  2. #include <QLineEdit>
  3. #include <QEvent>
  4. #include <QDebug>
  5. DoubleSpinBox::DoubleSpinBox(QWidget *parent)
  6. : QDoubleSpinBox(parent)
  7. {
  8. setButtonSymbols(QAbstractSpinBox::NoButtons);
  9. installEventFilter(this);
  10. setMaximum(1000000000);
  11. setMinimum(-100000000);
  12. m_lineEdit = this->lineEdit();
  13. connect(m_lineEdit, &QLineEdit::textChanged, this, [=]() {
  14. m_valueChangeFalg = true;
  15. });
  16. // 连接 editingFinished 信号来处理编辑完成事件
  17. connect(this, &QDoubleSpinBox::editingFinished, this, [=]() {
  18. if (m_valueChangeFalg)
  19. {
  20. emit editDone();
  21. }
  22. });
  23. }
  24. DoubleSpinBox::~DoubleSpinBox()
  25. {
  26. }
  27. bool DoubleSpinBox::eventFilter(QObject *watched, QEvent *event)
  28. {
  29. if (event->type() == QEvent::Wheel) {
  30. return true;
  31. } else {
  32. return QDoubleSpinBox::eventFilter(watched, event);
  33. }
  34. }