独立更改QStackedWidget每页的背景图像

时间:2017-06-14 05:19:47

标签: qt qt-creator qstylesheet qstackedwidget

我想独立更改堆叠小部件的每个页面的背景图像。但是,当我将背景图像添加到Qt创建者的styleSheet选项卡时,结果是堆叠小部件的所有页面都获得了该背景图像。 有没有办法在不使用QT的样式表格

的情况下为每个页面设置不同的背景图像

1 个答案:

答案 0 :(得分:1)

试试这个:

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);