2017-01-22 169 views
0

我怎樣才能簡單地設置我的QDialog背景?我可以很容易地設置背景的顏色,但是當我嘗試使用圖像時,我的背景變黑。我試圖用:QPallete與QBrush,樣式表:(QDialog - 設置背景圖片

回答

1

你可以簡單地

MyDialog::MyDialog(QWidget *parent) 
    : QDialog(parent) 
{ 
    ui.setupUi(this); 

    setStyleSheet("background-image:url(image.jpg);"); //this works 
} 

參見:Unable to set the background image in Qt Stylesheet

+0

遺憾的是它不工作:/我有我的資源.JPG,路徑是正確的,並且我的背景沒有任何變化:( – crooked

+0

@KCrookedHand - 您是否在應用程序中部署了imageformats文件夾?請參閱[autoFillBackground](http://doc.qt.io/qt-5/qwidget.html#autoFillBackground-道具)和[Qt圖像格式](http://doc.qt.io/qt-5/qwidget.html#autoFillBackground-prop) –