How to set QComboBox text color using setStyleSheet?
-
-
@TomNow99 said in How to set QComboBox text color using setStyleSheet?:
ui->comboBox->setStyleSheet("QListView::item:selected {background:red}");
Why do you use
QListView
here? The link states:The pop-up of the
QComboBox
is aQAbstractItemView
and is styled using the descendant selector:QComboBox QAbstractItemView { border: 2px solid darkgray; selection-background-color: lightgray; }
so why not read that and try that example?
-
-
@TomNow99
That will happen if you have not doneui->comboBox->setEditable(true)
, because it won't have a line edit. But you must have done that, because you want your combobox to be editable so that it has a line to type into, mustn't you....? Please take the time to read https://doc.qt.io/qt-5/qcombobox.html#lineEdit if you want to start usinglineEdit()
.I find you can also do
ui->comboBox->lineEdit().setObjectName("combobox"); Stylesheet: #combobox {color: green;}
if you prefer the ability to do it that way. I think you cannot access the
lineEdit()
from QSS just viaQComboBox QLineEdit { ... }
, for whatever reason.