2011-06-20 39 views
1

我在將背景圖像應用於QT表單時遇到了一個問題。 我應用於bg的圖像包含一些漸變效果,但在應用到背景後,其漸變效果正在進行。QT設置QT格式的背景圖像問題?

我使用下面的代碼在運行時將背景圖片:

QPalette palette; 
    palette.setBrush(this->backgroundRole(), QBrush(QImage("bg_all.png"))); 
    this->setPalette(palette); 

回答

2
QPalette palette; 
QString appDir = QApplication::applicationDirPath(); 
palette.setBrush(this->backgroundRole(),QBrush(QImage(appDir +"/bg.png"))); 
this->setPalette(palette); 

這就是爲我好。請檢查文件路徑是否正確。

2

如果你只是想添加背景形式,爲什麼不使用樣式表,而不是設置一個?

例如:

widget->setStylesheet("background-image: url(:/files/bg.png);")