天天看點

QT設定背景圖檔以及設定按鈕

1.Qt設定背景圖檔

         ①。設定UI視窗背景圖檔,需要在構造函數中添加以下代碼:

         this-> setAutoFillBackground(true);

         QPalette palette = this-> palette();

         Palette.setBrush(Qpalette ::視窗,QBrush(QPixmap的( “:RES / picture.png”)。

         縮放(這 - >尺寸(),Qt的:: IgnoreAspectRattio,

         Qt的:: smoothTransformation)));

         這 - >調用SetPalette(調色闆);

2.設定按鈕顔色,及字型方式

在UI界面選擇按鈕後在屬性欄裡找到樣式選項,添加以下代碼:

背景色:RGBA(100,255,100,30); //背景顔色

邊框樣式:開始; //邊框樣式

邊框寬度:4像素; //邊框寬度像素

3.Qt中利用标簽顯示圖檔,導緻圖檔不能顯示不全或者顯示的圖檔扭曲不成比例的解決辦法如下:

例:

QImage圖像;

Image.load( “:/ t.jpg”);

QPixmap pixmap = Qpixmap :: fromImage(Image);

int With = ui-> labpic-> width();

int height = ui-> labpic-> height();

//飽滿填充

QPixmap fitPixmap = pixmap.scaled(With,height,Qt :: IgnoreAspectRatio,Qt :: smoothTransformation);

//按比例縮放為标簽的大小

// QPixmap fitPixmap = pixmap.scaled(With,height,Qt :: keepAspectRatio,Qt :: smoothTransformation);

UI-> labpic-> setpixmap(fitPixmap);

4.顯示标簽圖檔有時需要将圖檔添加到資源,但添加大量圖檔後編譯會報錯,出現棧溢出,這時在.PRO檔案

中添加以下代碼,即可解決此問題:

           CONFIG + = resources_big

繼續閱讀