I am having trouble changing the highlight colour of a QCombobox in PyQt. I have managed to change the highlight colour of the actual input box but when the drop down appears it is still blue. The following images shows what is exactly happening. The palette method works on Linux but not on Windows (what I am currently using). I used PyQt palette:
brush = QtGui.QBrush(QtGui.QColor(168, 168, 168))
brush.setStyle(QtCore.Qt.SolidPattern)
palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Highlight, brush)
self.comboBox_7.setPalette(palette)
Here I managed to change the highlight colour to grey of the actual box:
but here the drop down highlight is still blue:
all help appreciated.
According to the Qt docs, the palette may not always work on some platforms:
Warning: Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the macOS styles.
The Qt Style Sheets Overview suggests that a stylesheet should work where the palette doesn't. I cannot test this myself on anything other than Linux, but the following seems to work okay:
from PyQt5 import QtWidgets
app = QtWidgets.QApplication([''])
combo = QtWidgets.QComboBox()
combo.addItems('One Two Three'.split())
combo.setStyleSheet('selection-background-color: rgb(168,168,168)')
combo.show()
app.exec_()