summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shaw <andy.shaw@qt.io>2017-09-25 13:03:25 +0200
committerAndy Shaw <andy.shaw@qt.io>2018-01-05 15:01:43 +0000
commit5e9e4ccdc363297f70d4ebfbbb3e279670eca553 (patch)
tree1d91d087097a4a192b1cc8935f94806bf84e6a4c
parentbef0db36ace4c49d77720e505e0953e1822d0d68 (diff)
Add an option to scroll the QComboBox on macOS with the mouse wheel
Since there may be some applications that want to make their comboboxes scrollable or not with the mouse wheel then a style hint is added to make this toggable. It defaults to true for all platforms except macOS to keep it in line with existing behavior. [ChangeLog][QtWidgets][QStyle] Added SH_ComboBox_AllowWheelScrolling as a style hint to enable/disable the use of the mouse wheel in a QComboBox. This defaults to true in all styles except the macOS one so there is no change in existing behavior. Task-number: QTBUG-53094 Change-Id: I6eb61e1990bfc79e3b3ea82d7b91ee39096fa077 Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io> Reviewed-by: Andy Nichols <andy.nichols@qt.io>
-rw-r--r--src/plugins/styles/mac/qmacstyle_mac.mm3
-rw-r--r--src/widgets/styles/qcommonstyle.cpp3
-rw-r--r--src/widgets/styles/qstyle.cpp5
-rw-r--r--src/widgets/styles/qstyle.h1
-rw-r--r--src/widgets/widgets/qcombobox.cpp9
-rw-r--r--tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp12
6 files changed, 22 insertions, 11 deletions
diff --git a/src/plugins/styles/mac/qmacstyle_mac.mm b/src/plugins/styles/mac/qmacstyle_mac.mm
index aee258fda0..e540ff4d3b 100644
--- a/src/plugins/styles/mac/qmacstyle_mac.mm
+++ b/src/plugins/styles/mac/qmacstyle_mac.mm
@@ -2963,6 +2963,9 @@ int QMacStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget *w
// min/max/close buttons on windows don't show tool tips
ret = false;
break;
+ case SH_ComboBox_AllowWheelScrolling:
+ ret = false;
+ break;
default:
ret = QCommonStyle::styleHint(sh, opt, w, hret);
break;
diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp
index e4d3c6a9e1..36cc6a22da 100644
--- a/src/widgets/styles/qcommonstyle.cpp
+++ b/src/widgets/styles/qcommonstyle.cpp
@@ -5290,6 +5290,9 @@ int QCommonStyle::styleHint(StyleHint sh, const QStyleOption *opt, const QWidget
case SH_Widget_Animation_Duration:
ret = styleHint(SH_Widget_Animate, opt, widget, hret) ? 200 : 0;
break;
+ case SH_ComboBox_AllowWheelScrolling:
+ ret = true;
+ break;
default:
ret = 0;
break;
diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp
index faa5f1e67e..101ff9fc16 100644
--- a/src/widgets/styles/qstyle.cpp
+++ b/src/widgets/styles/qstyle.cpp
@@ -1994,6 +1994,11 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
A value equal to zero means that the animations will be disabled.
This enum value has been introduced in Qt 5.10.
+ \value SH_ComboBox_AllowWheelScrolling
+ Determines if the mouse wheel can be used to scroll inside a QComboBox.
+ This is on by default in all styles except the Mac style.
+ This enum value has been introduced in Qt 5.10.
+
\sa styleHint()
*/
diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h
index f922aff7f1..ab61534a96 100644
--- a/src/widgets/styles/qstyle.h
+++ b/src/widgets/styles/qstyle.h
@@ -739,6 +739,7 @@ public:
SH_ItemView_ScrollMode,
SH_TitleBar_ShowToolTipsOnButtons,
SH_Widget_Animation_Duration,
+ SH_ComboBox_AllowWheelScrolling,
// Add new style hint values here
SH_CustomBase = 0xf0000000
diff --git a/src/widgets/widgets/qcombobox.cpp b/src/widgets/widgets/qcombobox.cpp
index b743af2569..4e8668b001 100644
--- a/src/widgets/widgets/qcombobox.cpp
+++ b/src/widgets/widgets/qcombobox.cpp
@@ -3350,11 +3350,11 @@ void QComboBox::keyReleaseEvent(QKeyEvent *e)
#if QT_CONFIG(wheelevent)
void QComboBox::wheelEvent(QWheelEvent *e)
{
-#ifdef Q_OS_DARWIN
- Q_UNUSED(e);
-#else
Q_D(QComboBox);
- if (!d->viewContainer()->isVisible()) {
+ QStyleOptionComboBox opt;
+ initStyleOption(&opt);
+ if (style()->styleHint(QStyle::SH_ComboBox_AllowWheelScrolling, &opt, this) &&
+ !d->viewContainer()->isVisible()) {
const int rowCount = count();
int newIndex = currentIndex();
@@ -3374,7 +3374,6 @@ void QComboBox::wheelEvent(QWheelEvent *e)
}
e->accept();
}
-#endif
}
#endif
diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
index c65cfa3e1a..0c229c9194 100644
--- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
+++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp
@@ -2052,13 +2052,13 @@ void tst_QComboBox::mouseWheel_data()
QTest::newRow("upper locked") << disabled << start << wheel << expected;
wheel = -1;
-#ifdef Q_OS_DARWIN
+ const bool allowsWheelScroll = QApplication::style()->styleHint(QStyle::SH_ComboBox_AllowWheelScrolling);
// on OS X & iOS mouse wheel shall have no effect on combo box
- expected = start;
-#else
- // on other OSes we should jump to next enabled item (no. 5)
- expected = 5;
-#endif
+ if (!allowsWheelScroll)
+ expected = start;
+ else // on other OSes we should jump to next enabled item (no. 5)
+ expected = 5;
+
QTest::newRow("jump over") << disabled << start << wheel << expected;
disabled.clear();