Unsolved How to set QComboBox text color using setStyleSheet?
-
-
@jsulm Thank you, but I saw this document. I don't see any example to QComboBox which I can use. But of course I can be wrong.
-
@TomNow99
The whole of that link is an example of customizingQComboBox
. -
@JonB I try:
ui->comboBox->setStyleSheet("QLineEdit {color: red}"); ui->comboBox->setStyleSheet("QListView::item:selected {background:red}");
and many other but with no good result.
-
@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?
-
@JonB I try this:
QComboBox QAbstractItemView { border: 2px solid darkgray; selection-background-color: lightgray; }
But this is not what I want. I don't want change items colors but only header color.
-
@TomNow99 said in How to set QComboBox text color using setStyleSheet?:
I don't want change items colors but only header color.
How does your proposed
ui->comboBox->setStyleSheet("QListView::item:selected {background:red}");
address that? -
@JonB I try many options. I would like that what I write in first post and add 2 example images. I only want change header text in QComboBox.
-
@TomNow99
One way of achieving that with stylesheet is:ui->comboBox->lineEdit()->setStyleSheet("color: red;");
-
@JonB When I do this my app crash because lineEdit() return QWidget(0x0).
I read that only editable QComboboxes have lineEdites()
-
@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.