Qt中按鈕背景圖片的切換設定

pamxy發表於2013-03-19

轉自:http://gjianw217.blog.163.com/blog/static/26144182012871551233/

第一種方法:

 

第二種方法:

使用setStyleSheet()函式進行設定:

如將一個QPushButton類的按鈕設定為:

ui->btn_name->setStyleSheet("QPushButton{background-image: url(:/images/call_up.bmp);}" 
"QPushButton:hover{background-image: url(:/images/call_hov.bmp);}" 
"QPushButton:pressed{background-image: url(:/images/call_down.bmp);}");

或者設定為字串的形式,在初始化時呼叫:

QString str="QPushButton#btn_name{background-image: url(:/images/call_up.bmp)}" 
                    "QPushButton#btn_name:hover{background-image: url(:/images/call_hov.bmp);}" 
                    "QPushButton#btn_name:pressed{background-image: url(:/images/call_down.bmp);}";

參考1  參考2


相關文章