Qt : Create SplashScreen

Qt : Create SplashScreen

This is a simple tutorial how Qt : Create SplashScreen. A splash screen is an image that appears while a game or program is loading. It may also be used to describe an introduction page on a website. Splash screens cover the entire screen or simply a rectangle near the center of the screen. The splash screens of operating systems and some applications that expect to be run full-screen usually cover the entire screen (wikipedia).

Qt have a class QSplashScreen to create SplashScreen. This is the sample code how Qt : Create SplashScreen :

#include <QApplication>
#include <QSplashScreen>
#include "mainwindow.h"
#include <QTimer>
#include <QThread>
class I : public QThread
{
public:
    static void sleep(unsigned long secs) {
        QThread::sleep(secs);
    }
};

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    QPixmap pix(":/new/prefix1/SplashScreen.png");
    QSplashScreen splash(pix);
    splash.show();

    //This line represents the alignment of text, color and position
    splash.showMessage(QObject::tr("Loading Programs........."),
                       Qt::AlignCenter | Qt::AlignBottom, Qt::black);
    qApp->processEvents();

    MainWindow w;
    I::sleep(6);               // Splash page is shown for 5 seconds
    w.show();
    splash.finish(&w);
    return a.exec();
}

Create a resource file and add your image png file. This is my sample resource file for this Qt : Create SplashScreen project :

<RCC>
    <qresource prefix="/new/prefix1">
        <file>SplashScreen.png</file>
    </qresource>
</RCC>

This is a sample output from this Qt : Create SplashScreen :

Qt_Create_SplashScreen

You can donwload the complete code for this Qt : Create SplashScreen at here.

Source :
http://www.developer.nokia.com/Community/Wiki/How_to_display_a_splash_screen_in_Qt

 

Add a Comment

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