Skip to content

Commit da78b38

Browse files
committed
fix: wheel event not propagating to parent in Qt6
Qt6 QApplication::notify pre-accepts wheel events (we.setAccepted(true)) before delivery. If a widget's wheelEvent doesn't call the parent class (which would ignore() the event), the event stays accepted and does not propagate to parent widgets (e.g. QScrollArea). This differs from Qt5 where unhandled wheel events propagated by default. Fix by overriding wheelEvent in DSpinBox, DDoubleSpinBox, DComboBox following the pattern from commit fe16c8e (settings/ComboBox): - hasFocus(): call base class wheelEvent (stepBy + accept, default behavior) - no focus: call QWidget::wheelEvent (ignore() -> event propagates) For DSlider, which is a QWidget containing an inner QSlider with an eventFilter on qApp, fix the eventFilter instead: when the inner slider has no focus, call e->ignore() before returning true so the event propagates to the parent scrollarea in Qt6. This fixes the Qt6-specific regression where scrolling over spinbox / combobox / slider inside a scrollarea was blocked. Ref: DDE-72
1 parent 1ce1547 commit da78b38

6 files changed

Lines changed: 53 additions & 5 deletions

File tree

‎include/widgets/dcombobox.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class LIBDTKWIDGETSHARED_EXPORT DComboBox : public QComboBox, public DCORE_NAMES
2323
protected:
2424
DComboBox(DComboBoxPrivate &dd, QWidget *parent);
2525

26+
void wheelEvent(QWheelEvent *event) override;
27+
2628
// QComboBox interface
2729
public:
2830
virtual void showPopup() override;

‎include/widgets/dslider.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

‎include/widgets/dspinbox.h‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2015 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -25,6 +25,10 @@ class LIBDTKWIDGETSHARED_EXPORT DSpinBox : public QSpinBox, public DTK_CORE_NAME
2525
public:
2626
explicit DSpinBox(QWidget *parent = nullptr);
2727

28+
protected:
29+
void wheelEvent(QWheelEvent *event) override;
30+
31+
public:
2832
QLineEdit *lineEdit() const;
2933

3034
bool isAlert() const;
@@ -65,6 +69,10 @@ class LIBDTKWIDGETSHARED_EXPORT DDoubleSpinBox : public QDoubleSpinBox, public D
6569
public:
6670
explicit DDoubleSpinBox(QWidget *parent = nullptr);
6771

72+
protected:
73+
void wheelEvent(QWheelEvent *event) override;
74+
75+
public:
6876
bool isAlert() const;
6977
void showAlertMessage(const QString &text, int duration = 3000);
7078
void showAlertMessage(const QString &text, QWidget *follower, int duration = 3000);

‎src/widgets/dcombobox.cpp‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include <QScreen>
3333
#include <QStack>
3434
#include <QWindow>
35+
#include <QWheelEvent>
3536

3637
DWIDGET_BEGIN_NAMESPACE
3738

@@ -109,6 +110,7 @@ DComboBox::DComboBox(QWidget *parent)
109110
{
110111
D_D(DComboBox);
111112
d->init();
113+
setFocusPolicy(Qt::StrongFocus);
112114
}
113115

114116
DComboBox::DComboBox(DComboBoxPrivate &dd, QWidget *parent)
@@ -117,6 +119,16 @@ DComboBox::DComboBox(DComboBoxPrivate &dd, QWidget *parent)
117119
{
118120
D_D(DComboBox);
119121
d->init();
122+
setFocusPolicy(Qt::StrongFocus);
123+
}
124+
125+
void DComboBox::wheelEvent(QWheelEvent *event)
126+
{
127+
if (hasFocus()) {
128+
QComboBox::wheelEvent(event);
129+
} else {
130+
QWidget::wheelEvent(event);
131+
}
120132
}
121133

122134
/*!

‎src/widgets/dslider.cpp‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2011 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2011 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -136,7 +136,11 @@ bool DSlider::eventFilter(QObject *watched, QEvent *e)
136136
Q_D(DSlider);
137137

138138
if ((watched == d->slider) && (e->type() == QEvent::Wheel)) {
139-
return !d->mouseWheelEnabled;
139+
if (d->mouseWheelEnabled && d->slider->hasFocus()) {
140+
return false; // let QSlider::wheelEvent handle it (stepBy + accept)
141+
}
142+
e->ignore(); // Qt6: un-accept so event propagates to parent (e.g. scrollarea)
143+
return true; // block delivery to the inner QSlider
140144
}
141145

142146
if (e->type() == QEvent::MouseButtonRelease) {

‎src/widgets/dspinbox.cpp‎

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2015 - 2022 UnionTech Software Technology Co., Ltd.
1+
// SPDX-FileCopyrightText: 2015 - 2026 UnionTech Software Technology Co., Ltd.
22
//
33
// SPDX-License-Identifier: LGPL-3.0-or-later
44

@@ -8,6 +8,8 @@
88
#include "private/dspinbox_p.h"
99
#include "dlineedit.h"
1010

11+
#include <QWheelEvent>
12+
1113
DWIDGET_BEGIN_NAMESPACE
1214

1315
DSpinBoxPrivate::DSpinBoxPrivate(DSpinBox *parent) :
@@ -63,6 +65,16 @@ DSpinBox::DSpinBox(QWidget *parent) :
6365
DObject(*new DSpinBoxPrivate(this))
6466
{
6567
d_func()->init();
68+
setFocusPolicy(Qt::StrongFocus);
69+
}
70+
71+
void DSpinBox::wheelEvent(QWheelEvent *event)
72+
{
73+
if (hasFocus()) {
74+
QSpinBox::wheelEvent(event);
75+
} else {
76+
QWidget::wheelEvent(event);
77+
}
6678
}
6779

6880
/*!
@@ -180,6 +192,16 @@ DDoubleSpinBox::DDoubleSpinBox(QWidget *parent) :
180192
DObject(*new DDoubleSpinBoxPrivate(this))
181193
{
182194
d_func()->init();
195+
setFocusPolicy(Qt::StrongFocus);
196+
}
197+
198+
void DDoubleSpinBox::wheelEvent(QWheelEvent *event)
199+
{
200+
if (hasFocus()) {
201+
QDoubleSpinBox::wheelEvent(event);
202+
} else {
203+
QWidget::wheelEvent(event);
204+
}
183205
}
184206

185207
bool DDoubleSpinBox::isAlert() const

0 commit comments

Comments
 (0)