2017-06-14 83 views
0

我想独立更改堆叠小部件的每个页面的背景图像。但是,当我将background-image:添加到Qt创建者的styleSheet选项卡时,结果是堆叠小部件的所有页面都会获取该背景图像。 有没有一种方法来设置使用QT的styleSheet方法独立更改QStackedWidget每个页面的背景图像

回答

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

好的,谢谢。我会尝试你的解决方案 –