ManhattanStyle: Remove a hack for QComboBox wheel scrolling

Use Utils::setWheelScrollingWithoutFocusBlocked() explicitly
when a QComboBox is placed inside a scroll area.

The Utils::setWheelScrollingWithoutFocusBlocked() is more
general and may be applied to other widgets, like QSpinBox.

This patch brings back the wheel scrolling without a modifier key
for combo boxes placed in dialogs.

Keep the unconditional scroll wheel behavior when ctrl (meta on mac)
modifier is pressed.

Change-Id: Ieea0f228cea6b59e276bd3256eb6ea5ecc5b7d14
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2023-12-07 14:29:14 +01:00
parent b49c40181a
commit 3a9c5a3e7d
2 changed files with 9 additions and 7 deletions

View File

@@ -2,19 +2,27 @@
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "guiutils.h"
#include "hostosinfo.h"
#include <QEvent>
#include <QGuiApplication>
#include <QWidget>
namespace Utils {
namespace Internal {
static bool isWheelModifier()
{
return QGuiApplication::keyboardModifiers()
== (HostOsInfo::isMacHost() ? Qt::MetaModifier : Qt::ControlModifier);
}
class WheelEventFilter : public QObject
{
public:
bool eventFilter(QObject *watched, QEvent *event) override {
if (event->type() == QEvent::Wheel) {
if (event->type() == QEvent::Wheel && !isWheelModifier()) {
QWidget *widget = qobject_cast<QWidget *>(watched);
if (widget && widget->focusPolicy() != Qt::WheelFocus && !widget->hasFocus()) {
QObject *parent = widget->parentWidget();

View File

@@ -436,12 +436,6 @@ int ManhattanStyle::styleHint(StyleHint hint, const QStyleOption *option, const
if (widget && widget->inherits("QTreeView"))
ret = 0;
break;
case QStyle::SH_ComboBox_AllowWheelScrolling:
// Turn this on only when simultaneously pressing Ctrl, to prevent accidental current
// index change, e.g. on a scroll view
ret = QGuiApplication::keyboardModifiers()
== (HostOsInfo::isMacHost() ? Qt::MetaModifier : Qt::ControlModifier);
break;
case QStyle::SH_Slider_AbsoluteSetButtons:
// Make QSlider jump on left mouse click
ret = Qt::LeftButton | Qt::MiddleButton | Qt::RightButton;