0
我想獨立更改堆疊小部件的每個頁面的背景圖像。但是,當我將background-image:添加到Qt創建者的styleSheet選項卡時,結果是堆疊小部件的所有頁面都會獲取該背景圖像。 有沒有一種方法來設置使用QT的styleSheet方法獨立更改QStackedWidget每個頁面的背景圖像
我想獨立更改堆疊小部件的每個頁面的背景圖像。但是,當我將background-image:添加到Qt創建者的styleSheet選項卡時,結果是堆疊小部件的所有頁面都會獲取該背景圖像。 有沒有一種方法來設置使用QT的styleSheet方法獨立更改QStackedWidget每個頁面的背景圖像
不同的背景圖像的每個頁面出來試試這個:
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);
好的,謝謝。我會嘗試你的解決方案 –