QComboBox color change
-
Stylesheets are just strings.
Nothing change in them unless u change the string and reapply with setStyleSheet.
I think you are after
QComboBox:editable {}
or if only when "open"
Docs says
"the pop-up of the QComboBox is a QAbstractItemView and is styled using the descendant selector:"
so maybe what u are after isQComboBoxQAbstractItemView {}
When stylesheets do nothing, it often syntax error or simply not the right selector.
-
I'm going to check the QAbstractItemView, maybe that's what I'm looking for you're right.
The thing I really don't understand is that my whole text and backgound is correctly set up when I open my combo box but when it's not there's a completly diffenrent setup (I can change the text font but not the color ) that's absurd ....
Coming back to you after a quick research.
-
@Amaury
-The thing I really don't understand is that my whole text and backgound is correctly set up when I open my combo boxWell if you use a selector like QComboBox it will not affect other types than QComboBox so it wont affect
the QAbstractItemView.
If you use QWidget as selector it affects all( from same parent)
but also buttons and stuff so its best to be exact.Think of it as u say:
Color all boxes.
And the thing combobox uses when open, is a circle so wont color it.So using selectors correctly makes it work much better :)
selector can be a name, a (class) type and sub item.http://doc.qt.io/qt-5/stylesheet-reference.html
This is important to understand to use stylesheets. -
-
@Amaury
A combox is multiple widgets.
There is the combox it selv, an edit control sometimes and
the dropdown area is a QAbstractItemView
and so on.
This goes for MOST widgets.
http://doc.qt.io/qt-5/stylesheet-reference.html
Look at all the differnt types for each Class.So yes, you cannot not just color the combo box and expect to work for all sub objects and types.
However, using QWidget as selector will affect it all. But its too broad.
So yes., its more complex than just think "i color the combobox" when you mean the
view's items. Its not the same. :) -
@Amaury !
Yes, test it out. once learned it make more sense.
For composite widgets like the combo box, its a bit more involving than for QPushButton.
Also know its cascading.
This is from setting "QWidget { background-color: rgb(170, 0, 127) ;}"
on the mainwindow.. -
Hi there I'm coming back to you and have to thank you I just understand how the stylesheets works now , I mean I was using the automatic parameters and was never specifiying any items like QComboBox or QPushButton.
I think I was stuck on that too long to notice what I was missing thank you a lot .