环境:windows10+vs2017+qt5.9.7
效果如下:分别为pushButton、LineEdit、ComboBox,
方法:Qwidget类的setstylesheet方法。
ui->lineEdit_s12->setStyleSheet("QLineEdit { background-color: red }");
ui->comboBox_Com->setStyleSheet("QComboBox { background-color: green }");
ui->pushButton->setStyleSheet("QPushButton { background-color: yellow }");
此外也可以通过stylesheet方法获取控件的颜色
qDebug() <<"combobox color :"<<ui->comboBox_Com->styleSheet();
结果如下: