转自: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);}";