#include #include #include #include // demonstrate the failure of polish/unpolish and setStyle(style) int main(int argc, char* argv[]) { QApplication a(argc, argv); a.setStyleSheet("QComboBox QAbstractItemView {selection-background-color:blue; background-color:white;} \ #fancy QAbstractItemView {selection-background-color:red; background-color:black;} "); QScopedPointer box(new QComboBox()); box->addItems({"...","Style(Normal)","Style(Fancy)","Polish/Unpolish","SetStyle(Style)","SetStyleSheet(StyleSheet)"}); box->setToolTip("A tooltip"); box->setObjectName("normal"); box->connect(box.data(), &QComboBox::currentTextChanged, [&box](const QString& text){ if(text == "Style(Normal)") { box->setObjectName("normal"); } else if (text == "Style(Fancy)") { box->setObjectName("fancy"); } else if (text == "Polish/Unpolish") { box->style()->unpolish(box.data()); box->style()->polish(box.data()); } else if (text == "SetStyle(Style)") { box->setStyle(box->style()); } else if (text == "SetStyleSheet(StyleSheet)") { box->setStyleSheet(box->styleSheet()); } }); box->show(); return a.exec(); }