Is is possible to apply a stylesheet to the popup portion of a QCompleter tied to a QCombobox? If not, does it require delegate magic? If so, how might that even work as they do tend to confuse the hell out of me. 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)
Would the popup styling take place in the combobox class, or would it happen outside of it where the data is input via addItems? Thanks in advance.
Set the stylesheet of the popup of the completer, which will be a QListView object. Here is a runnable example (the background of the popup 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_())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With