creasted spin boxes that allow mouse scroll changes only on active widgets

This commit is contained in:
Jakub Trllo 2023-02-09 20:26:49 +01:00
parent 7afbd4b9de
commit f6ee5db227
2 changed files with 32 additions and 0 deletions

View file

@ -1,4 +1,6 @@
from .widgets import (
FocusSpinBox,
FocusDoubleSpinBox,
CustomTextComboBox,
PlaceholderLineEdit,
BaseClickableFrame,
@ -34,6 +36,8 @@ from .overlay_messages import (
__all__ = (
"FocusSpinBox",
"FocusDoubleSpinBox",
"CustomTextComboBox",
"PlaceholderLineEdit",
"BaseClickableFrame",

View file

@ -13,6 +13,34 @@ from openpype.lib.attribute_definitions import AbstractAttrDef
log = logging.getLogger(__name__)
class FocusSpinBox(QtWidgets.QSpinBox):
"""QSpinBox which allow scroll wheel changes only in active state."""
def __init__(self, *args, **kwargs):
super(FocusSpinBox, self).__init__(*args, **kwargs)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def wheelEvent(self, event):
if not self.hasFocus():
event.ignore()
else:
super(FocusSpinBox, self).wheelEvent(event)
class FocusDoubleSpinBox(QtWidgets.QDoubleSpinBox):
"""QDoubleSpinBox which allow scroll wheel changes only in active state."""
def __init__(self, *args, **kwargs):
super(FocusDoubleSpinBox, self).__init__(*args, **kwargs)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
def wheelEvent(self, event):
if not self.hasFocus():
event.ignore()
else:
super(FocusDoubleSpinBox, self).wheelEvent(event)
class CustomTextComboBox(QtWidgets.QComboBox):
"""Combobox which can have different text showed."""