2017-01-22 1021 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) –