【问题标题】:Change background color in a specific widget of a Qt Stacked Widget在 Qt Stacked Widget 的特定小部件中更改背景颜色
【发布时间】:2015-03-26 14:39:55
【问题描述】:

我正在使用基于堆叠小部件的 Qt Creator 开发 Qt 应用程序。我想独立更改堆叠小部件每个页面的背景颜色(例如第一页蓝色,第二页红色等)。但是,当我将background-color: 添加到 Qt creator 上的 styleSheet 选项卡时,结果是堆叠小部件的所有页面都获得了该背景颜色。有没有办法为每个页面设置不同的背景颜色?

【问题讨论】:

    标签: qt widget qt-creator qstackedwidget


    【解决方案1】:

    您可以为每个小部件执行此操作:

    #page1 {
        background-color: blue;
    }
    #page2 {
        background-color: red;
    }
    

    #page1#page2 是对象名称,请在 Qt Creator 的 Object Inspector 侧面板中找到它们。

    【讨论】:

    • 这很简单!只是在任何地方都找不到。谢谢!
    【解决方案2】:
    // yep, you can change it in constructor of your widget.
    YourWidget::YourWidget(QWidget *parent):QWidget(parent),ui(new Ui::PageControl)
    {
        ui->setupUi(this);
        QPalette background(palette());
        background.setColor(QPalette::Background, Qt::black);
        this->setAutoFillBackground(true);
        this->setPalette(background);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-27
      • 2011-10-30
      • 2020-07-07
      • 2012-11-15
      • 2020-11-11
      • 1970-01-01
      • 2017-09-08
      相关资源
      最近更新 更多