From 61a06b3c43b4d3986d6af94d9a8e041480455f2c Mon Sep 17 00:00:00 2001 From: Matthias Puchner <github@mpuchner.de> Date: Fri, 22 Oct 2021 12:59:14 +0200 Subject: [PATCH] prevent accidental value change when scrolling the whole window with the mouse wheel --- GUI/Views/CommonWidgets/DoubleSpinBox.cpp | 10 ++++++++++ GUI/Views/CommonWidgets/DoubleSpinBox.h | 3 +++ 2 files changed, 13 insertions(+) diff --git a/GUI/Views/CommonWidgets/DoubleSpinBox.cpp b/GUI/Views/CommonWidgets/DoubleSpinBox.cpp index f08d4180743..c3ed8f23fb9 100644 --- a/GUI/Views/CommonWidgets/DoubleSpinBox.cpp +++ b/GUI/Views/CommonWidgets/DoubleSpinBox.cpp @@ -14,10 +14,12 @@ #include "GUI/Views/CommonWidgets/DoubleSpinBox.h" #include "GUI/Views/CommonWidgets/GUIHelpers.h" +#include <QWheelEvent> DoubleSpinBox::DoubleSpinBox(QWidget* parent, const DoubleDescriptor& d) : QDoubleSpinBox(parent), m_valueDescriptor(d) { + setFocusPolicy(Qt::StrongFocus); GUI::View::Helpers::configSpinbox(this, d.decimals, d.limits); setToolTip(d.tooltip); setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); @@ -75,6 +77,14 @@ void DoubleSpinBox::setBaseValue(double baseValue) setValue(toDisplayValue(baseValue)); } +void DoubleSpinBox::wheelEvent(QWheelEvent* event) +{ + if (!hasFocus()) + event->ignore(); + else + QDoubleSpinBox::wheelEvent(event); +} + void DoubleSpinBox::onDisplayValueChanged(double newDisplayValue) { emit baseValueChanged(toBaseValue(newDisplayValue)); diff --git a/GUI/Views/CommonWidgets/DoubleSpinBox.h b/GUI/Views/CommonWidgets/DoubleSpinBox.h index 103ede224bd..922ec6124c4 100644 --- a/GUI/Views/CommonWidgets/DoubleSpinBox.h +++ b/GUI/Views/CommonWidgets/DoubleSpinBox.h @@ -51,6 +51,9 @@ signals: //! newBaseValue is in the unit of the valueDescriptor. void baseValueChanged(double newBaseValue); +protected: + virtual void wheelEvent(QWheelEvent* event) override; + private: void onDisplayValueChanged(double newValue); -- GitLab