How to set QComboBox background color with QPalette?
-
It seems that none of the colors in the palette of QComboBox are used to draw its background. Only the drop down triangle is changed to white with this code. (I have no entries yet in the boxes.)
QPalette pal(palette()); QBrush brush(Qt::white); pal.setBrush(QPalette::Window, brush); pal.setBrush(QPalette::Background, brush); pal.setBrush(QPalette::WindowText, brush); pal.setBrush(QPalette::Foreground, brush); pal.setBrush(QPalette::Base, brush); pal.setBrush(QPalette::AlternateBase, brush); pal.setBrush(QPalette::ToolTipBase, brush); pal.setBrush(QPalette::ToolTipText, brush); pal.setBrush(QPalette::Text, brush); pal.setBrush(QPalette::Button, brush); pal.setBrush(QPalette::ButtonText, brush); pal.setBrush(QPalette::BrightText, brush); pal.setBrush(QPalette::Base, brush); pal.setBrush(QPalette::Light, brush); pal.setBrush(QPalette::Midlight, brush); pal.setBrush(QPalette::Dark, brush); pal.setBrush(QPalette::Mid, brush); pal.setBrush(QPalette::Shadow, brush); pal.setBrush(QPalette::NoRole, brush); setPalette(pal);
I tried to change the palette from designer too, but it appears that the background color of QComboBox is not defined in its palette, but determined elsewhere. How can I change the background color? If I use style sheet, QComboBox graphics reset to some really ugly look (since it has no default style sheet), but the background color changes.
-
Hi
Please try this
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);Also, a note on style sheets.
If u use a style sheet, its a all or nothing thing. (sadly)So when u set something, it will loose its images etc so
to change it, you must change most of it. -
You are right. In win 7 it changes nothing.
Sorry.