scantool过滤鼠标滚轮事件增加浮点型spinbox

This commit is contained in:
yangjiaxuan 2024-04-26 14:35:27 +08:00
parent 0db6f10642
commit 584abc4ca0
1 changed files with 15 additions and 13 deletions

View File

@ -167,7 +167,8 @@ std::vector<DeviceConfig> Form_DeviceConfig::GetDeviceConfigs()
bool Form_DeviceConfig::eventFilter(QObject *target, QEvent *event) bool Form_DeviceConfig::eventFilter(QObject *target, QEvent *event)
{ {
if (typeid(*target) == typeid(QSlider) || typeid(*target) == typeid(QComboBox) || typeid(*target) == typeid(QSpinBox)) if (typeid(*target) == typeid(QSlider) || typeid(*target) == typeid(QComboBox) || typeid(*target) == typeid(QSpinBox) ||
typeid(*target) == typeid(QDoubleSpinBox))
{ {
if (event->type() == QEvent::Wheel) if (event->type() == QEvent::Wheel)
{ {
@ -361,8 +362,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
// 创建控件 // 创建控件
QWidget *ctrl = nullptr; QWidget *ctrl = nullptr;
QWidget *extraCtrl = nullptr; QWidget *ctrlWidget = nullptr;
QWidget* sliderSpinWidget = new QWidget(scrollArea);
if (1 == deviceConfig.rangeType) if (1 == deviceConfig.rangeType)
{ {
@ -373,6 +373,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//comboBox->setCurrentText(QString::fromStdString(deviceConfig.stringValue)); //comboBox->setCurrentText(QString::fromStdString(deviceConfig.stringValue));
comboBox->installEventFilter(this); comboBox->installEventFilter(this);
ctrl = comboBox; ctrl = comboBox;
ctrlWidget = comboBox;
} }
else if (2 == deviceConfig.rangeType) else if (2 == deviceConfig.rangeType)
{ {
@ -383,6 +384,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//comboBox->setCurrentText(QString::number(deviceConfig.intValue)); //comboBox->setCurrentText(QString::number(deviceConfig.intValue));
comboBox->installEventFilter(this); comboBox->installEventFilter(this);
ctrl = comboBox; ctrl = comboBox;
ctrlWidget = comboBox;
} }
else if (3 == deviceConfig.rangeType) else if (3 == deviceConfig.rangeType)
{ {
@ -393,6 +395,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//comboBox->setCurrentText(QString::number(deviceConfig.doubleValue)); //comboBox->setCurrentText(QString::number(deviceConfig.doubleValue));
comboBox->installEventFilter(this); comboBox->installEventFilter(this);
ctrl = comboBox; ctrl = comboBox;
ctrlWidget = comboBox;
} }
else if (4 == deviceConfig.rangeType) else if (4 == deviceConfig.rangeType)
{ {
@ -413,11 +416,12 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int))); connect(spinBox, SIGNAL(valueChanged(int)), this, SLOT(on_spinBoxClicked(int)));
ctrl = slider; ctrl = slider;
extraCtrl = spinBox;
QHBoxLayout* hLayout = new QHBoxLayout; QHBoxLayout* hLayout = new QHBoxLayout;
hLayout->addWidget(ctrl); hLayout->addWidget(ctrl);
hLayout->addWidget(extraCtrl); hLayout->addWidget(spinBox);
QWidget* sliderSpinWidget = new QWidget(scrollArea);
sliderSpinWidget->setLayout(hLayout); sliderSpinWidget->setLayout(hLayout);
ctrlWidget = sliderSpinWidget;
} }
else if (5 == deviceConfig.rangeType) else if (5 == deviceConfig.rangeType)
{ {
@ -440,11 +444,12 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_doubleSpinboxClicked(double))); connect(doubleSpinBox, SIGNAL(valueChanged(double)), this, SLOT(on_doubleSpinboxClicked(double)));
ctrl = slider; ctrl = slider;
extraCtrl = doubleSpinBox;
QHBoxLayout* hLayout = new QHBoxLayout; QHBoxLayout* hLayout = new QHBoxLayout;
hLayout->addWidget(ctrl); hLayout->addWidget(ctrl);
hLayout->addWidget(extraCtrl); hLayout->addWidget(doubleSpinBox);
QWidget* sliderSpinWidget = new QWidget(scrollArea);
sliderSpinWidget->setLayout(hLayout); sliderSpinWidget->setLayout(hLayout);
ctrlWidget = sliderSpinWidget;
} }
else if (0 == deviceConfig.rangeType) else if (0 == deviceConfig.rangeType)
{ {
@ -461,6 +466,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//spinBox->setValue(deviceConfig.intValue); //spinBox->setValue(deviceConfig.intValue);
spinBox->installEventFilter(this); spinBox->installEventFilter(this);
ctrl = spinBox; ctrl = spinBox;
ctrlWidget = spinBox;
} }
else if (3 == deviceConfig.valueType) else if (3 == deviceConfig.valueType)
{ {
@ -480,13 +486,9 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
m_ctrlList.push_back(ctrl); m_ctrlList.push_back(ctrl);
} }
if (nullptr != extraCtrl) if (nullptr != ctrlWidget)
{ {
layout->addRow(label, sliderSpinWidget); layout->addRow(label, ctrlWidget);
}
else
{
layout->addRow(label, ctrl);
} }
} }