mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-02 00:44:52 +01:00
implemented delegate that can resize editor to required sizes
This commit is contained in:
parent
53027f6916
commit
2bc795197e
1 changed files with 59 additions and 4 deletions
|
|
@ -7,6 +7,65 @@ from .widgets import (
|
|||
from .multiselection_combobox import MultiSelectionComboBox
|
||||
|
||||
|
||||
class ResizeEditorDelegate(QtWidgets.QStyledItemDelegate):
|
||||
@staticmethod
|
||||
def _q_smart_min_size(editor):
|
||||
min_size_hint = editor.minimumSizeHint()
|
||||
size_policy = editor.sizePolicy()
|
||||
width = 0
|
||||
height = 0
|
||||
if size_policy.horizontalPolicy() != QtWidgets.QSizePolicy.Ignored:
|
||||
if (
|
||||
size_policy.horizontalPolicy()
|
||||
& QtWidgets.QSizePolicy.ShrinkFlag
|
||||
):
|
||||
width = min_size_hint.width()
|
||||
else:
|
||||
width = max(
|
||||
editor.sizeHint().width(),
|
||||
min_size_hint.width()
|
||||
)
|
||||
|
||||
if size_policy.verticalPolicy() != QtWidgets.QSizePolicy.Ignored:
|
||||
if size_policy.verticalPolicy() & QtWidgets.QSizePolicy.ShrinkFlag:
|
||||
height = min_size_hint.height()
|
||||
else:
|
||||
height = max(
|
||||
editor.sizeHint().height(),
|
||||
min_size_hint.height()
|
||||
)
|
||||
|
||||
output = QtCore.QSize(width, height).boundedTo(editor.maximumSize())
|
||||
min_size = editor.minimumSize()
|
||||
if min_size.width() > 0:
|
||||
output.setWidth(min_size.width())
|
||||
if min_size.height() > 0:
|
||||
output.setHeight(min_size.height())
|
||||
|
||||
return output.expandedTo(QtCore.QSize(0, 0))
|
||||
|
||||
def updateEditorGeometry(self, editor, option, index):
|
||||
self.initStyleOption(option, index)
|
||||
|
||||
option.showDecorationSelected = editor.style().styleHint(
|
||||
QtWidgets.QStyle.SH_ItemView_ShowDecorationSelected, None, editor
|
||||
)
|
||||
|
||||
widget = option.widget
|
||||
|
||||
style = widget.style() if widget else QtWidgets.QApplication.style()
|
||||
geo = style.subElementRect(
|
||||
QtWidgets.QStyle.SE_ItemViewItemText, option, widget
|
||||
)
|
||||
delta = self._q_smart_min_size(editor).width() - geo.width()
|
||||
if delta > 0:
|
||||
if editor.layoutDirection() == QtCore.Qt.RightToLeft:
|
||||
geo.adjust(-delta, 0, 0, 0)
|
||||
else:
|
||||
geo.adjust(0, 0, delta, 0)
|
||||
editor.setGeometry(geo)
|
||||
|
||||
|
||||
class NumberDelegate(QtWidgets.QStyledItemDelegate):
|
||||
def __init__(self, minimum, maximum, decimals, *args, **kwargs):
|
||||
super(NumberDelegate, self).__init__(*args, **kwargs)
|
||||
|
|
@ -34,10 +93,6 @@ class NumberDelegate(QtWidgets.QStyledItemDelegate):
|
|||
|
||||
return editor
|
||||
|
||||
# def updateEditorGeometry(self, editor, options, index):
|
||||
# print(editor)
|
||||
# return super().updateEditorGeometry(editor, options, index)
|
||||
|
||||
|
||||
class NameDelegate(QtWidgets.QStyledItemDelegate):
|
||||
def createEditor(self, parent, option, index):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue