Styling a QCompleter popup in PyQt

Can I apply a stylesheet to the QCompleter popup part bound to QCombobox? If not, does he need delegate magic? If so, how could this work, as they really drive me crazy. Here is my widget code:

class autoFillField(QComboBox): def __init__(self, parent=None): super(autoFillField, self).__init__(parent) self.setFocusPolicy(Qt.NoFocus) self.setEditable(True) self.addItem("") self.pFilterModel = QSortFilterProxyModel(self) self.pFilterModel.setFilterCaseSensitivity(Qt.CaseInsensitive) self.pFilterModel.setSourceModel(self.model()) self.completer = QCompleter(self.pFilterModel, self) self.completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion) self.setCompleter(self.completer) self.setStyleSheet(STYLING FOR COMBOBOX HERE, BUT NOT POPUP) self.lineEdit().textEdited[unicode].connect(self.pFilterModel.setFilterFixedString) def on_completer_activated(self, text): if text: index = self.findText(text) self.setCurrentIndex(index) def setModel(self, model): super(autoFillField, self).setModel(model) self.pFilterModel.setSourceModel(model) self.completer.setModel(self.pFilterModel) def setModelColumn(self, column): self.completer.setCompletionColumn(column) self.pFilterModel.setFilterKeyColumn(column) super(autoFillField, self).setModelColumn(column) 

Will the popup style go in the combobox class, or will it happen outside of it where the data is entered via addItems? Thanks in advance.

+7
source share
1 answer

Set the stylesheet for the add-on popup that will be the QListView object. Here is an example of execution (the popup window should be yellow):

 #!/usr/bin/python import sys from PyQt4 import QtGui, QtCore app = QtGui.QApplication(sys.argv) w = QtGui.QComboBox() w.setEditable(True) c = QtGui.QCompleter(['Hello', 'World']) c.setCompletionMode(QtGui.QCompleter.UnfilteredPopupCompletion) c.popup().setStyleSheet("background-color: yellow") w.setCompleter(c) w.show() sys.exit(app.exec_()) 
+14
source

All Articles