Change FocusPolicy of some PrefWidgets to StrongFocus

This commit mollifies the issue #17684 by making the PrefWidgets receive
mouse wheel events only when they have both focus and the mouse pointer
at the widget.
This commit is contained in:
xtemp09
2025-01-24 14:22:28 +07:00
committed by Chris Hennes
parent 5766974067
commit f818aa514c
2 changed files with 50 additions and 0 deletions

View File

@@ -169,6 +169,15 @@ void PrefWidget::failedToRestore(const QString& name) const
PrefSpinBox::PrefSpinBox ( QWidget * parent )
: QSpinBox(parent), PrefWidget()
{
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
}
void PrefSpinBox::wheelEvent(QWheelEvent *event)
{
if (hasFocus())
QSpinBox::wheelEvent(event);
else
event->ignore();
}
PrefSpinBox::~PrefSpinBox() = default;
@@ -201,6 +210,15 @@ void PrefSpinBox::savePreferences()
PrefDoubleSpinBox::PrefDoubleSpinBox ( QWidget * parent )
: QDoubleSpinBox(parent), PrefWidget()
{
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
}
void PrefDoubleSpinBox::wheelEvent(QWheelEvent *event)
{
if (hasFocus())
QDoubleSpinBox::wheelEvent(event);
else
event->ignore();
}
PrefDoubleSpinBox::~PrefDoubleSpinBox() = default;
@@ -332,6 +350,15 @@ void PrefFileChooser::savePreferences()
PrefComboBox::PrefComboBox ( QWidget * parent )
: QComboBox(parent), PrefWidget()
{
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
}
void PrefComboBox::wheelEvent(QWheelEvent *event)
{
if (hasFocus())
QComboBox::wheelEvent(event);
else
event->ignore();
}
PrefComboBox::~PrefComboBox() = default;
@@ -566,6 +593,15 @@ void PrefColorButton::savePreferences()
PrefUnitSpinBox::PrefUnitSpinBox ( QWidget * parent )
: QuantitySpinBox(parent), PrefWidget()
{
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
}
void PrefUnitSpinBox::wheelEvent(QWheelEvent *event)
{
if (hasFocus())
QuantitySpinBox::wheelEvent(event);
else
event->ignore();
}
PrefUnitSpinBox::~PrefUnitSpinBox() = default;
@@ -662,6 +698,7 @@ PrefQuantitySpinBox::PrefQuantitySpinBox (QWidget * parent)
: QuantitySpinBox(parent)
, d_ptr(new PrefQuantitySpinBoxPrivate())
{
setFocusPolicy(Qt::FocusPolicy::StrongFocus);
}
PrefQuantitySpinBox::~PrefQuantitySpinBox() = default;
@@ -708,6 +745,14 @@ void PrefQuantitySpinBox::contextMenuEvent(QContextMenuEvent *event)
}
}
void PrefQuantitySpinBox::wheelEvent(QWheelEvent *event)
{
if (hasFocus())
QuantitySpinBox::wheelEvent(event);
else
event->ignore();
}
void PrefQuantitySpinBox::restorePreferences()
{
Q_D(PrefQuantitySpinBox);