diff --git a/include/widgets/dcombobox.h b/include/widgets/dcombobox.h index 62b94cf11..34c53d56a 100644 --- a/include/widgets/dcombobox.h +++ b/include/widgets/dcombobox.h @@ -23,6 +23,8 @@ class LIBDTKWIDGETSHARED_EXPORT DComboBox : public QComboBox, public DCORE_NAMES protected: DComboBox(DComboBoxPrivate &dd, QWidget *parent); + void wheelEvent(QWheelEvent *event) override; + // QComboBox interface public: virtual void showPopup() override; diff --git a/include/widgets/dspinbox.h b/include/widgets/dspinbox.h index 8a14cbf1d..81520d0cd 100644 --- a/include/widgets/dspinbox.h +++ b/include/widgets/dspinbox.h @@ -25,6 +25,10 @@ class LIBDTKWIDGETSHARED_EXPORT DSpinBox : public QSpinBox, public DTK_CORE_NAME public: explicit DSpinBox(QWidget *parent = nullptr); +protected: + void wheelEvent(QWheelEvent *event) override; + +public: QLineEdit *lineEdit() const; bool isAlert() const; @@ -65,6 +69,10 @@ class LIBDTKWIDGETSHARED_EXPORT DDoubleSpinBox : public QDoubleSpinBox, public D public: explicit DDoubleSpinBox(QWidget *parent = nullptr); +protected: + void wheelEvent(QWheelEvent *event) override; + +public: bool isAlert() const; void showAlertMessage(const QString &text, int duration = 3000); void showAlertMessage(const QString &text, QWidget *follower, int duration = 3000); diff --git a/src/widgets/dcombobox.cpp b/src/widgets/dcombobox.cpp index 6867fe1ce..09a8e41e8 100644 --- a/src/widgets/dcombobox.cpp +++ b/src/widgets/dcombobox.cpp @@ -32,6 +32,7 @@ #include #include #include +#include DWIDGET_BEGIN_NAMESPACE @@ -119,6 +120,15 @@ DComboBox::DComboBox(DComboBoxPrivate &dd, QWidget *parent) d->init(); } +void DComboBox::wheelEvent(QWheelEvent *event) +{ + if (hasFocus()) { + QComboBox::wheelEvent(event); + } else { + QWidget::wheelEvent(event); + } +} + /*! * @~english @brief Override QComboBox::showPopup to limit the maximum display height according to maxVisibleItems(), which has a default value of 16. The maximum display height can be changed using setMaxVisibleItems(), which makes the setMaximumHeight() interface ineffective. diff --git a/src/widgets/dslider.cpp b/src/widgets/dslider.cpp index e10673ce2..e6666493a 100644 --- a/src/widgets/dslider.cpp +++ b/src/widgets/dslider.cpp @@ -136,7 +136,11 @@ bool DSlider::eventFilter(QObject *watched, QEvent *e) Q_D(DSlider); if ((watched == d->slider) && (e->type() == QEvent::Wheel)) { - return !d->mouseWheelEnabled; + if (d->mouseWheelEnabled && d->slider->hasFocus()) { + return false; // let QSlider::wheelEvent handle it (stepBy + accept) + } + e->ignore(); // Qt6: un-accept so event propagates to parent (e.g. scrollarea) + return true; // block delivery to the inner QSlider } if (e->type() == QEvent::MouseButtonRelease) { diff --git a/src/widgets/dspinbox.cpp b/src/widgets/dspinbox.cpp index 08543636b..9a7e087c7 100644 --- a/src/widgets/dspinbox.cpp +++ b/src/widgets/dspinbox.cpp @@ -8,6 +8,8 @@ #include "private/dspinbox_p.h" #include "dlineedit.h" +#include + DWIDGET_BEGIN_NAMESPACE DSpinBoxPrivate::DSpinBoxPrivate(DSpinBox *parent) : @@ -65,6 +67,15 @@ DSpinBox::DSpinBox(QWidget *parent) : d_func()->init(); } +void DSpinBox::wheelEvent(QWheelEvent *event) +{ + if (hasFocus()) { + QSpinBox::wheelEvent(event); + } else { + QWidget::wheelEvent(event); + } +} + /*! @~english @brief get the input line widget @@ -182,6 +193,15 @@ DDoubleSpinBox::DDoubleSpinBox(QWidget *parent) : d_func()->init(); } +void DDoubleSpinBox::wheelEvent(QWheelEvent *event) +{ + if (hasFocus()) { + QDoubleSpinBox::wheelEvent(event); + } else { + QWidget::wheelEvent(event); + } +} + bool DDoubleSpinBox::isAlert() const { D_DC(DDoubleSpinBox);