Qt C++ QComboBox Palette-setting the color (background-color)
How can I change the background-color QComboBox
without using styleSheet
?
Using this code:
QComboBox *cmb = new QComboBox(this);
QPalette palette = cmb->palette();
palette.setColor(QPalette::Base, Qt::red);
cmb->setPalette(palette);
QPalette view_palette = cmb->view()->palette();
view_palette.setColor(QPalette::Base, Qt::red);
cmb->view()->setPalette(view_palette);
cmb->addItem("1");
cmb->addItem("2");
cmb->addItem("2");
I get the following result: the drop-down list color changes to red, but the comboBox button remains the standard color - how do I change the color of the comboBox completely? (I attach a screenshot of the current result)
1
Author: user362803, 2019-12-07
1 answers
cmb->setEditable(true);
QLineEdit* lineEdit = cmb->lineEdit();
QPalette palette = lineEdit->palette();
palette.setColor(QPalette::Base, Qt::red);
lineEdit->setPalette(palette);
0
Author: magrif, 2019-12-07 12:43:02