How to Add a Splash Screen for Your Qt Application

Qt provides QSplashScreen class in case you want to have a splash screen for your application without any efforts. You can use the approach below to add an splash screen image of your choice using QSplashScreen and QPixmap classes that stays for 1 second and then disappears.

Change your application’s main.cpp file as shown below and it’s done!



Please note that you can also use a image added to Resources instead of a file saved to disk as is the case in example below:

#include "mainwindow.h"
#include <QApplication>
#include <QSplashScreen>
#include <QThread>

int main(int argc, char* argv[])
{
	QApplication app(argc, argv);
	QPixmap pixmap("c:/images/splash.png");
	QSplashScreen splash(pixmap);
	splash.show();
	app.thread()->sleep(1); // wait for just 1 second and then show main window
	app.processEvents();
	MainWindow window;
	window.show();
	splash.finish(&window);
	return app.exec();
}


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.