1. 效果图
2. 源码实现
2.1 设置 QPushButton 默认样式
QPushButton{
border:none;
border-image: url(:/image/close.png);
}
2.2 主要实现源码
void MainWindow::on_switch_btn_clicked()
{
if(m_switchisopen)
{
ui->switch_btn->setStyleSheet(
"QPushButton{\
border:none;\
border-image: url(:/image/close.png);\
}");
m_switchisopen = false;
}
else if(!m_switchisopen)
{
ui->switch_btn->setStyleSheet(
"QPushButton{\
border:none;\
border-image: url(:/image/open.png);\
}");
m_switchisopen = true;
}
}