根据不同状态给pushButton添加icon

cpp文件添加全局变量,表示全局状态

cpp

bool isSending=false; //播放和暂停的标志位

pushButton和槽函数链接

cpp

connect(m_ui->sendButton_2, &QPushButton::clicked, this, &SendFrameBox::on_sendCyclic_clicked);

槽函数定义

cpp

点击查看代码
void SendFrameBox::on_sendCyclic_clicked()
{
    QIcon icon;
    if(isSending==false)
    {
        //开始周期发送
        isSending = true;
        icon.addFile(QString::fromUtf8(":/images/stop_icon.png"), QSize(), QIcon::Normal, QIcon::On);
        m_ui->sendButton_2->setIcon(icon);
    }
    else
    {
        //停止周期发送
        isSending = false;
        icon.addFile(QString::fromUtf8(":/images/play_icon.png"), QSize(), QIcon::Normal, QIcon::On);
        m_ui->sendButton_2->setIcon(icon);
    }
}
posted @ 2025-06-15 15:59  ShererYANG  阅读(11)  评论(0)    收藏  举报