首页 > 解决方案 > 主窗口打开后显示一个按钮

问题描述

如何在主窗口打开 10 秒后立即显示按钮?

我正在使用 showevent 但如果我在其中进行 10 秒计数,它就会卡住:

void main::showEvent(QShowEvent *event)
{
   QWidget::showEvent( event );
   QTimer timer;
    timer.start(10000);

    while(timer.remainingTime() > 0)
    {
       qDebug() << timer.remainingTime();
        if(timer.remainingTime() <= 0)
        {
            _ui->btn_CloseAd->show();
            timer.stop();
        }
    }
}

解决方案是什么?

标签: c++qt

解决方案


void main::showEvent(QShowEvent *event)
{
   QWidget::showEvent( event );
   QTimer::singleShot(10000, _ui->btn_CloseAd, &QWidget::show);
}

推荐阅读