美文网首页
Qt 等待界面(菊花转)

Qt 等待界面(菊花转)

作者: Caiaolun | 来源:发表于2020-06-07 17:29 被阅读0次

    原文地址: https://blog.csdn.net/liang19890820/article/details/51029355

    QTimer通过setInterval设置100毫秒超时时间,每隔100毫秒后进行图标的更换,达到旋转效果。

    MainWindow::MainWindow(QWidget *parent)
        : CustomWindow(parent),
          m_nIndex(1)
    {
        m_pLoadingLabel = new QLabel(this);
        m_pTipLabel = new QLabel(this);
        m_pTimer = new QTimer(this);
    
        m_pTipLabel->setText(QString::fromLocal8Bit("拼命加载中..."));
    
        // 设定超时时间100毫秒
        m_pTimer->setInterval(100);
        connect(m_pTimer, &QTimer::timeout, this, &MainWindow::updatePixmap);
    
        startAnimation();
    }
    
    // 启动定时器
    void MainWindow::startAnimation()
    {
        m_pTimer->start();
    }
    
    // 停止定时器
    void MainWindow::stopAnimation()
    {
        m_pTimer->stop();
    }
    
    // 更新图标
    void MainWindow::updatePixmap()
    {
        // 若当前图标下标超过8表示到达末尾,重新计数。
        m_nIndex++;
        if (m_nIndex > 8)
            m_nIndex = 1;
    
        QPixmap pixmap(QString(":/Images/loading%1").arg(m_nIndex));
        m_pLoadingLabel->setPixmap(pixmap);
    }
    

    相关文章

      网友评论

          本文标题:Qt 等待界面(菊花转)

          本文链接:https://www.haomeiwen.com/subject/txnctktx.html