通过css让这样一张图片显示在按钮上
QPushButton {
border: 0px;
border-radius: 37px;
background-image: url(':/file/carLightButton.png');margin-left:0px; margin-top:0px;
width: 212px;
height: 74px;
}
QPushButton:hover:!pressed {
margin-left:-212px; margin-top:0px;
}
QPushButton:pressed {
margin-left:-424px ; margin-top:0px;
}
QPushButton:flat {
border: none;
}
QPushButton:default {
border-color: navy;
}/*BIG_C_GOD*/
把这些代码写到文件里,在程序内读取即可
btn = new QPushButton(this);
QFile file(":/file/qss.qss");
file.open(QFile::ReadOnly);
QString styleSheet = QLatin1String(file.readAll());
btn->setStyleSheet(styleSheet);
file.close();