mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 16:34:53 +01:00
added value cleanup to filter combobox
This commit is contained in:
parent
0795df31c4
commit
84b42581ff
2 changed files with 23 additions and 8 deletions
|
|
@ -130,6 +130,10 @@ class TypeDelegate(QtWidgets.QStyledItemDelegate):
|
|||
if index >= 0:
|
||||
editor.setCurrentIndex(index)
|
||||
|
||||
def setModelData(self, editor, model, index):
|
||||
editor.value_cleanup()
|
||||
super(TypeDelegate, self).setModelData(editor, model, index)
|
||||
|
||||
|
||||
class ToolsDelegate(QtWidgets.QStyledItemDelegate):
|
||||
def __init__(self, tools_cache, *args, **kwargs):
|
||||
|
|
|
|||
|
|
@ -65,20 +65,31 @@ class FilterComboBox(QtWidgets.QComboBox):
|
|||
super(FilterComboBox, self).focusInEvent(event)
|
||||
self.lineEdit().selectAll()
|
||||
|
||||
def focusOutEvent(self, event):
|
||||
idx = self.currentIndex()
|
||||
if idx > -1:
|
||||
index = self.model().index(idx, 0)
|
||||
text = index.data(QtCore.Qt.DisplayRole)
|
||||
if text != self.lineEdit().text():
|
||||
self.lineEdit().setText(text)
|
||||
super(FilterComboBox, self).focusOutEvent(event)
|
||||
def value_cleanup(self):
|
||||
text = self.lineEdit().text()
|
||||
idx = self.findText(text)
|
||||
if idx < 0:
|
||||
count = self._completer.completionModel().rowCount()
|
||||
if count > 0:
|
||||
index = self._completer.completionModel().index(0, 0)
|
||||
text = index.data(QtCore.Qt.DisplayRole)
|
||||
idx = self.findText(text)
|
||||
|
||||
if idx < 0:
|
||||
idx = 0
|
||||
self.setCurrentIndex(idx)
|
||||
|
||||
def on_completer_activated(self, text):
|
||||
if text:
|
||||
index = self.findText(text)
|
||||
self.setCurrentIndex(index)
|
||||
|
||||
def keyPressEvent(self, event):
|
||||
if event.key() in (QtCore.Qt.Key_Return, QtCore.Qt.Key_Enter):
|
||||
self.value_cleanup()
|
||||
|
||||
super(FilterComboBox, self).keyPressEvent(event)
|
||||
|
||||
def setModel(self, model):
|
||||
super(FilterComboBox, self).setModel(model)
|
||||
self._filter_proxy_model.setSourceModel(model)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue