常见的启动方式:
Qt制作简单和高级SplashScreen(程序启动页面):https://blog.csdn.net/u014597198/article/details/68061239
Qt-QSplashScreen-程序启动动画:https://blog.csdn.net/z609932088/article/details/79382321
Qt学习16——程序启动画面QSplashScreen:https://blog.csdn.net/u014266675/article/details/74174047
以上内容,关于SplashScreen的介绍都非常的详细。
如果现在需要在程序的运行中,有一段占用时间较长的程序要执行,比如各类算法,迭代等等,此时除去progressDialog之外
想使用SplashScreen,具体实现方式如下:
头文件:
#include<QSplashScreen>
#include<QPixmap>
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include<QSplashScreen>
#include<QPixmap>
#define num 12
namespace Ui {
class Widget;
}
class Widget : public QWidget
{
Q_OBJECT
public:
explicit Widget(QWidget *parent = 0);
~Widget();
void logic();
void prepare();//假定,在执行此函数的时候,进行SplashScreen
void end();//在执行到次函数的时候,结束SplashScreen
private:
Ui::Widget *ui;
QPixmap pixmap;
QSplashScreen * splash;
};
#endif // WIDGET_H
源文件:
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
//.....
splash = new QSplashScreen(this);//分配空间
pixmap.load("://image/未标题-1.jpg");//加载要溅射的图片
splash->setPixmap(pixmap);
//.....
}
//.....
//.....
void Widget::prepare()
{
//........
splash->show();//开启
splash->repaint();//需要重绘
//........
}
void Widget::end()
{
//........
splash->close();//关闭
//........
}
void Widget::logic()
{
//........
prepare();
end();
//........
}
以上情况是启动和关闭在不同的类方法定义中;
如果实际情况简单,不需要在不同的类方法定义中进行分开启动和关闭
可以进行简化(加载图片和SplashScreen类的定义都可以放在类方法定义中,不用定义为成员变量)
Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
//.....
splash = new QSplashScreen(this);//分配空间
pixmap.load("://image/未标题-1.jpg");//加载要溅射的图片
splash->setPixmap(pixmap);
//.....
}
//.....
//.....
void Widget::prepare()
{
//........
//........
}
void Widget::end()
{
//........
//........
}
void Widget::logic()
{
splash->show();//启动
//........
prepare();
end();
//........
splash->close();//关闭
}