I am trying to set the background color for a double spin box, and I am not sure what function I should use.
I saw some function called SetBackgroundRole
which accepts a Qt::ColorRole
, but I am not sure how to use this one as well.
Kindly let me know, what's the simple way to change the background color of a QComboBox
or QDoubleSpinBox
?
To make sure your background color will be correct, I would suggest to use the Qt Style Sheet. Here is what I did to change the background color of a QComboBox : myComboBox->setStyleSheet("QComboBox { background-color: blue; }");
fhe is generally correct, but doesn't account for the widgets (like spin boxes and buttons/comboboxes) that use a different background role in the palette. A more general solution would be something like this:
QPalette pal = widget.palette(); pal.setColor(widget.backgroundRole(), Qt::blue); widget.setPalette(pal);
Alternatively, you could look into the descriptions of the various palette roles and figure out the one you want, then apply it to the widget containing the others you want changed. The palette changes should propagate to the children widgets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With