Qt 如何设置QLineEdit、QPushButton、QCheckBox等颜色——stylesheet

环境:windows10+vs2017+qt5.9.7

效果如下:分别为pushButton、LineEdit、ComboBox,

Qt 如何设置QLineEdit、QPushButton、QCheckBox等颜色——stylesheet_第1张图片

方法: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 :"<comboBox_Com->styleSheet();

结果如下:

Qt 如何设置QLineEdit、QPushButton、QCheckBox等颜色——stylesheet_第2张图片

你可能感兴趣的:(QT5问题及解决方法,Qt,控件颜色)