Only allow scroll wheel edits when spinbox is active

(cherry picked from commit ebc3d626d152a07692f2de598c294348ad199597)
This commit is contained in:
Roy Nieterau 2022-02-08 17:06:59 +01:00
parent 13266d005c
commit a5273cb758
2 changed files with 31 additions and 3 deletions

View file

@ -2,7 +2,9 @@ from Qt import QtWidgets, QtCore
from .widgets import (
NameTextEdit,
FilterComboBox
FilterComboBox,
SpinBoxScrollFixed,
DoubleSpinBoxScrollFixed
)
from .multiselection_combobox import MultiSelectionComboBox
@ -89,9 +91,9 @@ class NumberDelegate(QtWidgets.QStyledItemDelegate):
def createEditor(self, parent, option, index):
if self.decimals > 0:
editor = QtWidgets.QDoubleSpinBox(parent)
editor = DoubleSpinBoxScrollFixed(parent)
else:
editor = QtWidgets.QSpinBox(parent)
editor = SpinBoxScrollFixed(parent)
editor.setObjectName("NumberEditor")
# Set min/max

View file

@ -429,3 +429,29 @@ class ConfirmProjectDeletion(QtWidgets.QDialog):
def _on_confirm_text_change(self):
enabled = self._confirm_input.text() == self._project_name
self._confirm_btn.setEnabled(enabled)
class SpinBoxScrollFixed(QtWidgets.QSpinBox):
"""QSpinBox which only allow edits change with scroll wheel when active"""
def __init__(self, *args, **kwargs):
super(SpinBoxScrollFixed, self).__init__(*args, **kwargs)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def wheelEvent(self, event):
if not self.hasFocus():
event.ignore()
else:
super(SpinBoxScrollFixed, self).wheelEvent(event)
class DoubleSpinBoxScrollFixed(QtWidgets.QDoubleSpinBox):
"""QDoubleSpinBox which only allow edits with scroll wheel when active"""
def __init__(self, *args, **kwargs):
super(DoubleSpinBoxScrollFixed, self).__init__(*args, **kwargs)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def wheelEvent(self, event):
if not self.hasFocus():
event.ignore()
else:
super(DoubleSpinBoxScrollFixed, self).wheelEvent(event)