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)
相关文章推荐
- QT学习 第一章:基本对话框
- 使用Shiboken为C++和Qt库创建Python绑定
- Qt 5.6更新至RC版,最终版本近在咫尺
- Qt定时器和随机数详解
- Qt实现图片移动实例(图文教程)
- Qt for Android开发实例教程
- QModelIndex/Role/Model介紹<二>
- 基于PyQt5的快速开发框架QFramer
- OSX下安装PyQt
- ok6410开发板移植DirectFB手记
- 【笔记】给Qt内嵌一个Chrome吧
- 【算法】最短路径之A*搜索
- qt入门必备
- 在 Qt4 中使用 C++11
- Hello Word ~ v0.2.2 背单词软件发布 -- By WHYPRO
- ubuntu下opencv和qt的安装配置
- linux下opengl的安装(with qt)
- qt 学习小节
- QT编译时Cannot find -lGL
- QT的命名风格