12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #include "DoubleSpinBox.h"
- #include <QLineEdit>
- #include <QEvent>
- #include <QDebug>
- DoubleSpinBox::DoubleSpinBox(QWidget *parent)
- : QDoubleSpinBox(parent)
- {
- setButtonSymbols(QAbstractSpinBox::NoButtons);
- installEventFilter(this);
- setMaximum(1000000000);
- setMinimum(-100000000);
- m_lineEdit = this->lineEdit();
- connect(m_lineEdit, &QLineEdit::textChanged, this, [=]() {
- m_valueChangeFalg = true;
- });
- // 连接 editingFinished 信号来处理编辑完成事件
- connect(this, &QDoubleSpinBox::editingFinished, this, [=]() {
- if (m_valueChangeFalg)
- {
- emit editDone();
- }
- });
- }
- DoubleSpinBox::~DoubleSpinBox()
- {
- }
- bool DoubleSpinBox::eventFilter(QObject *watched, QEvent *event)
- {
- if (event->type() == QEvent::Wheel) {
- return true;
- } else {
- return QDoubleSpinBox::eventFilter(watched, event);
- }
- }
|