QComboBox 在更改主要 windows 背景时变得丑陋

QComboBox become ugly when changing main windows background

更改前:

将父控件 styleSheet 属性 更改为:

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

我看到了这个:

QComboBox变得真的不一样了。发生什么了?如何在深色背景下使用常规QComboBox?

我正在使用没有 QML 的 Qt 5.5。

您必须将其设置为主 window 仅

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

或者告诉 QComboBox 没有样式: yourWindow->setStyleSheet("QComboBox{background-color:none}");

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

根据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).

如果你只想改变一些颜色,保持所选样式不变,更好的解决方案是使用 QPalette.