How to create a splash screen with an induced delay: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
(Fixed example making just brute-force blocking synchronous sleep)
 
(7 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=How to create a splash screen with an induced delay.=
{{LangSwitch}}
[[Category:HowTo]]
We have {{DocLink|QSplashScreen}} which is used to cover up the starting delay of the program. Some times the programs might be quick enough, so that the splash screen may not be visible. We may induce some delay to show the splash, as a decoration!


We have [http://doc.qt.nokia.com/latest/qsplashscreen.html QSplashScreen] ''[doc.qt.nokia.com]'' which is used to cover up the starting delay of the program. More about splash screen is [http://doc.qt.nokia.com/latest/qsplashscreen.html here] ''[doc.qt.nokia.com]''.<br /> Some times the programs might be quick enough ,so that the splash screen may not be visible. We may induce some delay to show the splash , as a decoration !
Single shot timer {{DocLink|QTimer}} will do.


Here in this example, using [http://doc.qt.nokia.com/latest/qthread.html QThread] ''[doc.qt.nokia.com]'' a delay is induced.
<code>
#include <QApplication>
#include <QSplashScreen>
#include <QTimer>
#include "mainwindow.h"


Easy! Happy coding!
int main(int argc, char *argv[])
 
{
===Categories:===
    QApplication app(argc, argv);
 
    QPixmap pixmap("splash.jpg");
* [[:Category:HowTo|HowTo]]
    QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);
* [[:Category:snippets|snippets]]
    splash.show();
    QTimer::singleShot(5000, &splash, &QWidget::close); // keep displayed for 5 seconds
    MainWindow mainWin;
    mainWin.showMaximized();
    return app.exec();
}
</code>

Latest revision as of 06:54, 21 June 2019

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

We have QSplashScreen which is used to cover up the starting delay of the program. Some times the programs might be quick enough, so that the splash screen may not be visible. We may induce some delay to show the splash, as a decoration!

Single shot timer QTimer will do.

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

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    QPixmap pixmap("splash.jpg");
    QSplashScreen splash(pixmap, Qt::WindowStaysOnTopHint);
    splash.show();
    QTimer::singleShot(5000, &splash, &QWidget::close); // keep displayed for 5 seconds
    MainWindow mainWin;
    mainWin.showMaximized();
    return app.exec();
}