1

I am developing a Qt application using Qt Creator that is based on a stacked widget. I would like to independently change the background color of each page of the stacked widget (e.g. first page blue, second page red, etc.). However, when I add background-color: to the styleSheet tab on Qt creator, the result is that all the pages of the stacked widget get that background color. Is there a way to set a different background color to each page?

maupertius
  • 1,518
  • 4
  • 17
  • 30

2 Answers2

4

You can do it per widget:

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

Where #page1 and #page2 are the object names, find them on the Object Inspector side panel in Qt Creator.

svlasov
  • 9,923
  • 2
  • 38
  • 39
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);
}