效果如圖:
1.將資源放在工程目錄下:
2.設計ui,並把新增到xx.qrc資源檔案中:
3.去掉邊框並設定透明,載入背景,繫結
cgloble::setbuttonstyle(ui.btn_xt,":/paycount_qt/pic/xt.png",3);
cgloble::setbuttonstyle(ui.btn_user,":/paycount_qt/pic/guser.png",3);
cgloble::setbuttonstyle(ui.btn_book,":/paycount_qt/pic/book.png",3);
cgloble::setbuttonstyle(ui.btn_pro,":/paycount_qt/pic/pro.png",3);
cgloble::setbuttonstyle(ui.btn_log,":/paycount_qt/pic/rz.png",3);
cgloble::setbuttonstyle(ui.btn_min,":/paycount_qt/pic/min.png",3);
cgloble::setbuttonstyle(ui.btn_max,":/paycount_qt/pic/max.png",3);
cgloble::setbuttonstyle(ui.btn_close,":/paycount_qt/pic/close.png",3);
setwindowflags(qt::framelesswindowhint);//去掉邊框
setattribute(qt::wa_translucentbackground);//透明
///背景載入;
m_pixmapbg.load(":/paycount_qt/pic/frame.png");
setbuttonstyle的函式定義如下:
//按鈕切片 imgsrc:路徑 cutsec:切多少片
void cgloble::setbuttonstyle(qpushbutton *button, qstring imgsrc, int cutsec)
")
.arg(img_w).arg(imgsrc).arg(0).arg(picwidth*1).arg(picwidth*2));
}
4.重寫各種事件,實現部分就不貼出來了,如果需要可檢視原始碼 Qt 介面美化
1.設定窗體透明 qwidget pwidget setstylesheet background color rgba 255,255,255,0 border style solid border width 0px border color rgba 255,255,255,0 2.設定窗體背...
QT學習之路 QT介面的美化
只需要在建構函式中新增 setwindowflags qt framelesswindowhint 函式即可 ui pushbutton setstylesheet border image url me.png this setobjectname dialog 這句話一定要有,不然,整個介面上的...
QT學習之路 QT介面的美化
只需要在建構函式中新增 setwindowflags qt framelesswindowhint 函式即可 ui pushbutton setstylesheet border image url me.png this setobjectname dialog 這句話一定要有,不然,整個介面上的...