Merge pull request #4447 from ynput/feature/attr_defs_widget_enhancements

AttrDefs: Enhancements of AttrDefs widgets
This commit is contained in:
Jakub Trllo 2023-02-10 11:00:27 +01:00 committed by GitHub
commit fbca1348ba
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 3 deletions

View file

@ -16,7 +16,11 @@ from openpype.lib.attribute_definitions import (
UISeparatorDef,
UILabelDef
)
from openpype.tools.utils import CustomTextComboBox
from openpype.tools.utils import (
CustomTextComboBox,
FocusSpinBox,
FocusDoubleSpinBox,
)
from openpype.widgets.nice_checkbox import NiceCheckbox
from .files_widget import FilesWidget
@ -142,6 +146,9 @@ class AttributeDefinitionsWidget(QtWidgets.QWidget):
if attr_def.label:
label_widget = QtWidgets.QLabel(attr_def.label, self)
tooltip = attr_def.tooltip
if tooltip:
label_widget.setToolTip(tooltip)
layout.addWidget(
label_widget, row, 0, 1, expand_cols
)
@ -243,10 +250,10 @@ class NumberAttrWidget(_BaseAttrDefWidget):
def _ui_init(self):
decimals = self.attr_def.decimals
if decimals > 0:
input_widget = QtWidgets.QDoubleSpinBox(self)
input_widget = FocusDoubleSpinBox(self)
input_widget.setDecimals(decimals)
else:
input_widget = QtWidgets.QSpinBox(self)
input_widget = FocusSpinBox(self)
if self.attr_def.tooltip:
input_widget.setToolTip(self.attr_def.tooltip)

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."""