Merge pull request #2981 from pypeclub/bugfix/OP-2990_Settings-UI-Version-input-widget-is-broken-on-some-linux-dist

Settings UI: Fix version completer on linux
This commit is contained in:
Jakub Trllo 2022-03-31 13:37:57 +02:00 committed by GitHub
commit a9f2292f10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,6 +97,9 @@ class CompleterView(QtWidgets.QListView):
QtCore.Qt.FramelessWindowHint
| QtCore.Qt.Tool
)
# Open the widget unactivated
self.setAttribute(QtCore.Qt.WA_ShowWithoutActivating)
delegate = QtWidgets.QStyledItemDelegate()
self.setItemDelegate(delegate)
@ -225,10 +228,18 @@ class SettingsLineEdit(PlaceholderLineEdit):
def __init__(self, *args, **kwargs):
super(SettingsLineEdit, self).__init__(*args, **kwargs)
self._completer = None
# Timer which will get started on focus in and stopped on focus out
# - callback checks if line edit or completer have focus
# and hide completer if not
focus_timer = QtCore.QTimer()
focus_timer.setInterval(50)
focus_timer.timeout.connect(self._on_focus_timer)
self.textChanged.connect(self._on_text_change)
self._completer = None
self._focus_timer = focus_timer
def _on_text_change(self, text):
if self._completer is not None:
self._completer.set_text_filter(text)
@ -240,19 +251,19 @@ class SettingsLineEdit(PlaceholderLineEdit):
new_point = self.mapToGlobal(point)
self._completer.move(new_point)
def _on_focus_timer(self):
if not self.hasFocus() and not self._completer.hasFocus():
self._completer.hide()
self._focus_timer.stop()
def focusInEvent(self, event):
super(SettingsLineEdit, self).focusInEvent(event)
self.focused_in.emit()
if self._completer is None:
return
self._completer.show()
self._update_completer()
def focusOutEvent(self, event):
super(SettingsLineEdit, self).focusOutEvent(event)
if self._completer is not None:
self._completer.hide()
self._focus_timer.start()
self._completer.show()
self._update_completer()
def paintEvent(self, event):
super(SettingsLineEdit, self).paintEvent(event)