SpinBox.cpp 749 B

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