#include "customsplashscreen.h"
#include <QPixmap>
#include <QThread>
#include <QDateTime>
#include <QApplication>
#include <QProgressBar>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QDebug>
#define DELAYTIME 1000 // DELAYTIME为需要延时的毫秒数
#define SHOWNO 3 // 显示加载次数
CustomSplashScreen::CustomSplashScreen(QWidget *parent) : QSplashScreen(parent)
{
QString strScreen = "./ss.jpg";
QFont font = this->font();
font.setPixelSize(23);
setFont(font);
QPixmap loadingPix(strScreen);
setPixmap(loadingPix.scaled(500, 300));
m_pProgressBar = new QProgressBar(this);
m_pProgressBar->setRange(0 ,100);
m_pProgressBar->setValue(0);
m_pProgressBar->setStyleSheet("QProgressBar{color:#ff0000;}");
QLabel* pLabel = new QLabel("加载中...");
pLabel->setStyleSheet("QLabel {color:#ff0000; font-weight: bold; font-style: italic; font-size: 23px;}");
QHBoxLayout* pHB = new QHBoxLayout();
pHB->addStretch();
pHB->addWidget(pLabel);
pHB->addStretch();
QVBoxLayout* pVB = new QVBoxLayout(this);
pVB->addStretch();
pVB->addLayout(pHB);
pVB->addWidget(m_pProgressBar);
this->setLayout(pVB);
}
void CustomSplashScreen::init()
{
// 先设置显示,再设置显示信息,如果设置完显示信息再设置显示,会看不到
show();
// 设置鼠标指针不转圈
QApplication::setOverrideCursor(Qt::ArrowCursor);
// 显示信息,及文本对齐方式:右上, 字体:red
showMessage("程序正在加载...", Qt::AlignTop|Qt::AlignRight, Qt::red);
QDateTime time = QDateTime::currentDateTime();
QDateTime currentTime = QDateTime::currentDateTime(); // 记录当前时间
m_pProgressBar->setValue(0);
int nInter = time.msecsTo(currentTime);
while(nInter <= DELAYTIME)
{
currentTime = QDateTime::currentDateTime();
m_pProgressBar->setValue(0.025*nInter);
nInter = time.msecsTo(currentTime);
}
for(int i = 0; i < SHOWNO; ++i)
{
showMessage(QString("请稍等%1...").arg(SHOWNO-i), Qt::AlignTop|Qt::AlignRight, Qt::red);
time = currentTime;
nInter = time.msecsTo(currentTime);
while(nInter <= DELAYTIME)
{
currentTime = QDateTime::currentDateTime();
m_pProgressBar->setValue(25*(i+1) + 0.025*nInter);
nInter = time.msecsTo(currentTime);
}
}
m_pProgressBar->setValue(100);
}
没有合适的资源?快使用搜索试试~ 我知道了~
【Qt之QSplashScreen】开场动画使用:进度条加载及设置鼠标指针不转圈
共9个文件
cpp:3个
h:2个
ui:1个
3 下载量 109 浏览量
2023-11-16
18:38:13
上传
评论 1
收藏 787KB RAR 举报
温馨提示
【Qt之QSplashScreen】开场动画使用:进度条加载及设置鼠标指针不转圈
资源推荐
资源详情
资源评论
收起资源包目录
splashScreen.rar (9个子文件)
splashScreen
mainwindow.h 319B
mainwindow.cpp 478B
main.cpp 288B
mainwindow.ui 2KB
bin
ss.jpg 457KB
untitled56.exe 1.54MB
customsplashscreen.cpp 3KB
customsplashscreen.h 399B
untitled56.pro 1KB
共 9 条
- 1
资源评论
FreeLikeTheWind.
- 粉丝: 1522
- 资源: 7
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功