QComboBox palette not working
-
QPalette and QComboBox are included.
QPalette oriPal; //at the .h file oriPal = cbBox->palette(); oriPal.setColor(QPalette::Base, Qt::red); cbBox->setPalette(oriPal);
Here is list of possible roles for every element of widget, you can scroll not so far to the ColorRole.
None of them working in my app except QPalette::Text .
So text of my ComboBox(and it's contains) are possible to change, but anything else - no. Why?
-
Hi,
What version of Qt are you using ?
On what platform ?Note that the platform is allowed to ignore values of the palette so it might be what is happening.
-
@SGaist said in QComboBox palette not working:
Note that the platform is allowed to ignore values of the palette so it might be what is happening.
Definitely not. Since i mentioned at the beginning that palette of textColors are applied to my ComboBoxes, so that is not igrnoring.
-
@Engelard
Hi
Some platforms QStyle might not use ( as in ignore) some of the roles.
Some roles that worked on linux had no effect in Windows in my app.
http://doc.qt.io/qt-5/style-reference.htmlAlso, the Qcombobox is actually a view and uses the models role hints which
might not use palette that much for "items"
https://code.woboq.org/qt5/qtbase/src/widgets/widgets/qcombobox.cpp.html -
@mrjj said in QComboBox palette not working:
Im not sure what you want to color,
simple BG-color, with palette it would be 2 lines of code, with stylesheet it 6(alot of conversons to each color from QCOlor, then it convert to string, lots of extrawork).
-
@Engelard
You can also do
ui->comboBox->setItemData( 0, QColor( Qt::black ), Qt::BackgroundRole );
ui->comboBox->setItemData( 1, QColor( Qt::red ), Qt::BackgroundRole );
since its uses an (internal) model. and is basically a view like Listview etc. -
@mrjj said in QComboBox palette not working:
@Engelard
You can also do
ui->comboBox->setItemData( 0, QColor( Qt::black ), Qt::BackgroundRole );
ui->comboBox->setItemData( 1, QColor( Qt::red ), Qt::BackgroundRole );Hey, that's pretty good!
But it applied only for items inside(which great, will use in future maybe), i still can't find something like ->setData(); so it would be applied for comboBox container it'self.
-
@Engelard
well the roles in the model is only use for items and not for the view
http://doc.qt.io/qt-5/qcombobox.html#viewbut it tried your code and it did work for me ??
-
@Engelard
HiQPalette oriPal; //at the .h file oriPal = cbBox->palette(); oriPal.setColor(QPalette::Base, Qt::red); cbBox->setPalette(oriPal);
did color it red as picture showed.
so it did use QPalette::Base ( Qt 5.11, windows)