QComboBox become ugly when changing main windows background

373 Views Asked by At

Before changing:

enter image description here

After changing parent widget styleSheet property to this:

background-color: rgb(5, 34, 78);

I see this:

enter image description here

QComboBox become really different. What happens? How to use regular QComboBox on dark background?

I am using Qt 5.5 without QML.

2

There are 2 best solutions below

0
On BEST ANSWER

You have to set it to the main window only

yourWindow->setStyleSheet("{background-color: #HexNumber}");

or tell the QComboBox to not have style: yourWindow->setStyleSheet("QComboBox{background-color:none}");

or

yourWindow->setStyleSheet("QComboBox#ComboName{background-color:none}");

0
On

According to manual:

When a style sheet is active, the QStyle returned by QWidget::style() is a wrapper "style sheet" style, not the platform-specific style. The wrapper style ensures that any active style sheet is respected and otherwise forwards the drawing operations to the underlying, platform-specific style (e.g., QWindowsXPStyle on Windows XP).

If all you want is to change some colors, leaving selected style unchanged, the better solution would be to use QPalette.