C++ Qt Gui应用程序背景色样式表

C++ Qt Gui应用程序背景色样式表,c++,css,qt,user-interface,stylesheet,C++,Css,Qt,User Interface,Stylesheet,我想为我的表单设置背景色 像这样 body { background-color: #fff; } 我正在使用QWidget选择器,但我只想更改窗口背景 以及如何为所有窗口使用一个样式表?您可以为任何QWdiget设置特定的样式表。如果它是您的主窗口,您可以执行以下操作: QString style = "QMainWindow { background-color: #fff; }"; // or other color this->setStyleSheet(style); /

我想为我的表单设置背景色

像这样

body
{
  background-color: #fff;
}
我正在使用QWidget选择器,但我只想更改窗口背景


以及如何为所有窗口使用一个样式表?

您可以为任何
QWdiget
设置特定的样式表。如果它是您的主窗口,您可以执行以下操作:

QString style = "QMainWindow { background-color: #fff; }";  // or other color
this->setStyleSheet(style); // assuming you are calling from the QMainWindow inherited class
您可以对主窗口中的单个小部件执行相同的操作,例如对实例化为
标签的
QLabel

QString style = "QLabel { background-color: #fff; }";  // or other color
label->setStyleSheet(style);
您还可以将另一个小部件的所有子部件作为目标,或者指定一个子部件。看看