Search code examples
qtwidgetqt-creatorqstackedwidget

Change background color in a specific widget of a Qt Stacked Widget


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?


Solution

  • 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.