【发布时间】:2012-08-15 03:17:45
【问题描述】:
我想为我的表单设置背景颜色
喜欢这个
body
{
background-color: #fff;
}
我正在使用 QWidget 选择器,但我只想更改窗口背景;
我怎样才能为所有窗口创建一个样式表?
【问题讨论】:
标签: c++ css qt user-interface stylesheet
我想为我的表单设置背景颜色
喜欢这个
body
{
background-color: #fff;
}
我正在使用 QWidget 选择器,但我只想更改窗口背景;
我怎样才能为所有窗口创建一个样式表?
【问题讨论】:
标签: c++ css qt user-interface stylesheet
您可以为任何QWdiget 设置特定样式表。如果它是您的主窗口,您可以这样做:
QString style = "QMainWindow { background-color: #fff; }"; // or other color
this->setStyleSheet(style); // assuming you are calling from the QMainWindow inherited class
您可以对主窗口中的单个小部件执行相同操作,例如对实例化为 label 的 QLabel:
QString style = "QLabel { background-color: #fff; }"; // or other color
label->setStyleSheet(style);
您还可以定位另一个的所有子小部件或指定单个子小部件。看看http://doc.qt.io/archives/qt-4.7/stylesheet-examples.html
【讨论】: