利用QSplashScreen类实现在程序启动过程中显示启动画面的功能

#include <QMainWindow>

class SplashScren : public QMainWindow
{
	Q_OBJECT

public:
	SplashScren(QWidget *parent = Q_NULLPTR);
};
#include "SplashScreen.h"
#include<QTextEdit>
#include<windows.h>
#pragma execution_character_set("utf-8")
SplashScren::SplashScren(QWidget *parent)
	: QMainWindow(parent)
{
	setWindowTitle("主界面");
	QTextEdit *edit = new QTextEdit;
	edit->setText("hello world");
	setCentralWidget(edit);
	resize(600,400);
	Sleep(1000);
}
#include "SplashScreen.h"
#include <QApplication>
#include <QPixmap>
#include <QSplashScreen>
int main(int argc, char *argv[])
{
	QApplication a(argc, argv);

	QPixmap pixmap(":/SplashScreen/1");
	QSplashScreen splash(pixmap);
	splash.show();
	a.processEvents();                 //使程序在显示启动画面的同时仍能响应鼠标等其他事件
	SplashScren w;
	w.show();
	splash.finish(&w);                 //在主窗口对象初始化完成后,结束启动画面
	return a.exec();
}

猜你喜欢

转载自blog.csdn.net/m0_37806112/article/details/80472661