independently change the background image of each page of QStackedWidget

835 views Asked by At

I would like to independently change the background image of each page of the stacked widget . However, when I add background-image: to the styleSheet tab on Qt creator, the result is that all the pages of the stacked widget get that background image. Is there a way to set a different background image to each page with out using QT's styleSheet Method

1

There are 1 answers

0
snoopy On

Try this:

QWidget *widget = stackWidget->currentWidget();
QPixmap background("/home/user/Pictures/background.png");
bkgnd = background.scaled(widget->size(), Qt::IgnoreAspectRatio);
QPalette palette;
palette.setBrush(QPalette::Background, background);
widget->setPalette(palette);