Combobox completer popup is locked out in modal dialog
-
I am trying to use a filtering combobox which filters the list of combo entries based on user input to the line edit. All works as expected except if the dialog is modal, the user can not interact with the popup list to select an item. It seems the popup is not part of the dialog and hence disabled. If I run the dialog as non modal (dlg.show() instead of dlg.exec()) everything works.
What am I missing. filtering combobox code is below.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
class FilteringComboBox(QComboBox):
def init(self, parent=None, **kwargs):
QComboBox.init(self, parent, editable=True, focusPolicy=Qt.StrongFocus, **kwargs)self._proxy=QSortFilterProxyModel(self, filterCaseSensitivity=Qt.CaseInsensitive) self._proxy.setSourceModel(self.model()) self._completer=QCompleter( self._proxy, self, activated=self.onCompleterActivated ) self._completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion) self.setCompleter(self._completer) self.lineEdit().textEdited.connect(self._proxy.setFilterFixedString) self.currentIndexChanged.connect(self.onCurrentIndexChanged) @pyqtSlot(int) def onCurrentIndexChanged(self, data): print("changed to index: {}, value: {}, code: {}".format(data, self.itemText(data), self.currentData(role=Qt.UserRole+1))) @pyqtSlot(str) def onCompleterActivated(self, text): if not text: return self.setCurrentIndex(self.findText(text)) self.activated[str].emit(self.currentText())
-
Hi and welcome to devnet,
Isn't that what QCompleter already does ?