QT设计程序启动时的画面

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38784098/article/details/77884547

1.新建项目"SplashSreen"

2.示例代码:

SplashSreen.cpp

#include "SplashSreen.h"
//添加头文件
#include <QTextEdit.h>
#include <windows.h>

SplashSreen::SplashSreen(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
	setWindowTitle("Splash Example");
	QTextEdit *edit = new QTextEdit;
	edit->setText("Splash Example!");
	setCentralWidget(edit);

	resize(600, 400);
	Sleep(1000);//休眠时间
}
main.cpp

#include "SplashSreen.h"
#include <QtWidgets/QApplication>
//添加头文件
#include <QPixmap>
#include <QSplashScreen>
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
	QPixmap pixmap(":/new/prefix1/Resources/anchor.png");//在图标下载一个图标,有才的也可以自己设计
	QSplashScreen spalsh(pixmap);
	spalsh.show();//显示此图标
	a.processEvents();
    SplashSreen w;
    w.show();
	spalsh.finish(&w);
    return a.exec();
}
3.运行效果

中央先出现图标一秒钟,再出现主界面




猜你喜欢

转载自blog.csdn.net/qq_38784098/article/details/77884547