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)
{
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)
{
@ -361,8 +362,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
// 创建控件
QWidget *ctrl = nullptr;
QWidget *extraCtrl = nullptr;
QWidget* sliderSpinWidget = new QWidget(scrollArea);
QWidget *ctrlWidget = nullptr;
if (1 == deviceConfig.rangeType)
{
@ -373,6 +373,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//comboBox->setCurrentText(QString::fromStdString(deviceConfig.stringValue));
comboBox->installEventFilter(this);
ctrl = comboBox;
ctrlWidget = comboBox;
}
else if (2 == deviceConfig.rangeType)
{
@ -383,6 +384,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//comboBox->setCurrentText(QString::number(deviceConfig.intValue));
comboBox->installEventFilter(this);
ctrl = comboBox;
ctrlWidget = comboBox;
}
else if (3 == deviceConfig.rangeType)
{
@ -393,6 +395,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//comboBox->setCurrentText(QString::number(deviceConfig.doubleValue));
comboBox->installEventFilter(this);
ctrl = comboBox;
ctrlWidget = comboBox;
}
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)));
ctrl = slider;
extraCtrl = spinBox;
QHBoxLayout* hLayout = new QHBoxLayout;
hLayout->addWidget(ctrl);
hLayout->addWidget(extraCtrl);
hLayout->addWidget(spinBox);
QWidget* sliderSpinWidget = new QWidget(scrollArea);
sliderSpinWidget->setLayout(hLayout);
ctrlWidget = sliderSpinWidget;
}
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)));
ctrl = slider;
extraCtrl = doubleSpinBox;
QHBoxLayout* hLayout = new QHBoxLayout;
hLayout->addWidget(ctrl);
hLayout->addWidget(extraCtrl);
hLayout->addWidget(doubleSpinBox);
QWidget* sliderSpinWidget = new QWidget(scrollArea);
sliderSpinWidget->setLayout(hLayout);
ctrlWidget = sliderSpinWidget;
}
else if (0 == deviceConfig.rangeType)
{
@ -461,6 +466,7 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
//spinBox->setValue(deviceConfig.intValue);
spinBox->installEventFilter(this);
ctrl = spinBox;
ctrlWidget = spinBox;
}
else if (3 == deviceConfig.valueType)
{
@ -480,13 +486,9 @@ void Form_DeviceConfig::Init(SANE_Handle devHandle)
m_ctrlList.push_back(ctrl);
}
if (nullptr != extraCtrl)
if (nullptr != ctrlWidget)
{
layout->addRow(label, sliderSpinWidget);
}
else
{
layout->addRow(label, ctrl);
layout->addRow(label, ctrlWidget);
}
}