diff options
author | Tasuku Suzuki <[email protected]> | 2023-10-13 16:21:45 +0900 |
---|---|---|
committer | Tasuku Suzuki <[email protected]> | 2023-10-17 01:55:14 +0000 |
commit | f1085b324eb27f9a4d2c2d67243a3ba015e34b22 (patch) | |
tree | 855dd66d1847e931e77a6c2fa86137299884a7ff /src/libs/utils/guiutils.cpp | |
parent | 13f5367611af2084eca5202428f1e0cacec9f0bf (diff) |
ProjectExplorer: Avoid accidental changes on spinbox via mouse scroll
- Introduced an Utils::attachWheelBlocker() to disable mouse wheel events on the "Parallel Jobs" field.
- This prevents unintentional modifications when users inadvertently scroll over the input.
Change-Id: Iccb93305fbcf399cae683412078782b5ea9f4ad6
Reviewed-by: <[email protected]>
Reviewed-by: Jarek Kobus <[email protected]>
Diffstat (limited to 'src/libs/utils/guiutils.cpp')
-rw-r--r-- | src/libs/utils/guiutils.cpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/libs/utils/guiutils.cpp b/src/libs/utils/guiutils.cpp new file mode 100644 index 00000000000..bfafff677f7 --- /dev/null +++ b/src/libs/utils/guiutils.cpp @@ -0,0 +1,34 @@ +// Copyright (C) 2023 Tasuku Suzuki <[email protected]> +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 + +#include "guiutils.h" + +#include <QEvent> +#include <QWidget> + +namespace Utils { + +namespace Internal { + +class WheelEventFilter : public QObject +{ +public: + bool eventFilter(QObject *watched, QEvent *event) override { + auto widget = qobject_cast<QWidget *>(watched); + return event->type() == QEvent::Wheel + && widget + && widget->focusPolicy() != Qt::WheelFocus + && !widget->hasFocus(); + } +}; + +} // namespace Internal + +void QTCREATOR_UTILS_EXPORT attachWheelBlocker(QWidget *widget) +{ + static Internal::WheelEventFilter instance; + widget->installEventFilter(&instance); + widget->setFocusPolicy(Qt::StrongFocus); +} + +} // namespace Utils |