您的位置:首页 > 编程语言 > Qt开发

Qt之等待提示框(QTimer)

2016-03-31 19:17 495 查看

简述

上节讲述了关于QPropertyAnimation实现等待提示框的显示,本节我们使用另外一种方案来实现-使用定时器QTimer,通过设置超时时间定时更新图标达到旋转效果。

简述

效果

资源

源码

更多参考

效果



资源

需要几张不同阶段的图标进行切换,这里使用8张。



源码

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之等待提示框(QPropertyAnimation)

Qt之QProgressIndicator(等待提示框)

Qt之等待提示框(QMovie)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息