【问题标题】:Qt Gui Application background color stylesheetQt Gui 应用程序背景颜色样式表
【发布时间】:2012-08-15 03:17:45
【问题描述】:

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

喜欢这个

body
{
  background-color: #fff;
}

我正在使用 QWidget 选择器,但我只想更改窗口背景;

我怎样才能为所有窗口创建一个样式表?

【问题讨论】:

    标签: c++ css qt user-interface stylesheet


    【解决方案1】:

    您可以为任何QWdiget 设置特定样式表。如果它是您的主窗口,您可以这样做:

    QString style = "QMainWindow { background-color: #fff; }";  // or other color
    this->setStyleSheet(style); // assuming you are calling from the QMainWindow inherited class
    

    您可以对主窗口中的单个小部件执行相同操作,例如对实例化为 labelQLabel

    QString style = "QLabel { background-color: #fff; }";  // or other color
    label->setStyleSheet(style);
    

    您还可以定位另一个的所有子小部件或指定单个子小部件。看看http://doc.qt.io/archives/qt-4.7/stylesheet-examples.html

    【讨论】:

      猜你喜欢
      • 2012-09-14
      • 2011-06-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-04
      • 2015-06-17
      • 2013-04-05
      相关资源
      最近更新 更多