Question

I have created a Qt HMI with QtDesigner and ui files. My QComboBox doesn't have the same background color in the designer and in real:

Designer:

enter image description here

Real life:

enter image description here

I am under Windows 7. Maybe it is OS dependent but I would like to have a white background.

I tried:

comboBox->setStyleSheet("QComboBox { background-color: white; }");

but it also paints the right arrow.

Any explanation?

Was it helpful?

Solution 3

The QPalette::Base does not change the background of the QComboBox.

Instead I've used:

QPalette palette = ui->combo->palette();
palette.setColor(QPalette::Active, QPalette::Button, Qt::white);
palette.setColor(QPalette::Inactive, QPalette::Button, Qt::white);
ui->combo->setPalette(palette);

and it seems to work.

OTHER TIPS

Is the combo empty?

Try adding some elements and select one of them before running the "app".

Did you try changing QPalette::Base to white? You can do it without using any stylesheet.

QComboBox box = new QComboBox();
QPalette p = box.palette();

p.setColor(QPalette::Active, QPalette::Base, Qt::white);
p.setColor(QPalette::Inactive, QPalette::Base, Qt::white);

box.setPalette(p);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top