1

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

4

2 回答 2

4

您可以按小部件执行此操作:

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

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

于 2015-03-26T15:00:08.510 回答
0
// 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);
}
于 2015-05-22T01:49:28.790 回答