一、实现间隔一秒只能点击一次按钮(没到时间之前,点击不能按)
void MainWindow::on_btnInfoNotice_clicked()
{
ui->btnInfoNotice->setEnabled(false);
QTimer::singleShot(1000, this, [=]() {
ui->btnInfoNotice->setEnabled(true);
});
}
二、第二种方法,适用于操作过快toast提示
void MainWindow::on_btnInfoNotice_clicked()
{
if (m_RefreshTimer == nullptr) {
m_RefreshTimer = new QTimer(this);
m_RefreshTimer->setInterval(100);
m_RefreshTimer->setSingleShot(true);
}
if (m_RefreshTimer->isActive()) {
QString tips = "操作过于频繁,请稍后再试";
} else {
m_RefreshTimer->start();
}
}