Create Slpash Screen
-
Hi,
I want To Create A splash Screen for My Application
i wrote This Code But when i start app Instantly Viewed and THEN instantly
Non-View!
this is my code and what i must do to set show time off splash screed?int main(int argc, char *argv[]) { QApplication app(argc, argv); QSplashScreen *splash = new QSplashScreen; splash->setPixmap(QPixmap(":/images/splash.png")); splash->show(); Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop; splash->showMessage(QObject::tr("Setting up the main window..."), topRight, Qt::white); MainWindow mainWin; splash->showMessage(QObject::tr("Loading modules..."), topRight, Qt::white); loadModules(); splash->showMessage(QObject::tr("Establishing connections..."), topRight, Qt::white); establishConnections(); mainWin.show(); splash->finish(&mainWin); delete splash; return app.exec(); }
-
Hi might be this,
QApplication app(argc, argv); QPixmap pixmap(":/new/prefix1/Icons/SplashScreen.png"); QSplashScreen splash(pixmap); splash.show(); //This line represents the alignment of text, color and position splash.showMessage(QObject::tr("Initiating..."),Qt::AlignLeft, Qt::white); app.processEvents(); Sleep(3000); MainWindow win; win.showMaximized(); splash.finish(&win); return app.exec();
-
@M4RZB4Ni I think you probably just copied that code from: http://www.qtcentre.org/archive/index.php/t-45572.html. Even though that is not important it does indicate to me that you have not really searched for an answer on your own. Anyway, I would say the easiest way to see whether the splash screen is working properly (testing it) is by using the QTest namespace as follows:
#include "MyClass.h" // #include "MainWindow.h" in your case #include <QtGui/QApplication> #include <QSplashScreen> #include <QTest> // The testing namespace int main(int argc, char *argv[]) { QApplication app(argc, argv); QSplashScreen *splash = new QSplashScreen; // May also be allocated on the stack instead splash->setPixmap(QPixmap(":MyClass/Resources/images/Qt Logo.png")); // Replace with a path to your own image splash->show(); Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop; splash->showMessage(QObject::tr("Setting up the main window..."), topRight, Qt::white); QTest::qSleep(1000); // Sleeps the application for 1 second and blocks processing of events splash->showMessage(QObject::tr("Loading modules..."), topRight, Qt::white); MyClass myClass; // Is MainWindow win in your case QTest::qSleep(1000); //myClass.loadModules(); Have not implemented this function splash->showMessage(QObject::tr("Establishing connections..."), topRight, Qt::white); QTest::qSleep(1000); //myClass.establishConnections(); Idem myClass.show(); splash->finish(&myClass); delete splash; return app.exec(); }
The calls to QTest::qSleep(1000) sleep the application for a 1000 milliseconds (no event processing). You can also replace it with QTest::qWait(1000) (with event processing). AFAIK there is no specific function that is part of the QSplashScreen library which you can use to set a display time for the splash screen.
If you always want to sleep the application for a few seconds to show the splash screen and thereby temporarily prevent the execution of the rest of your program then I would use @Ratzz method.
-
Hi,
Never use the QtTest module in production code. It's a framework for unit testing.
Out of curiosity, why do you want to slow down your application startup to show a splash screen ?
-
This will give you the base to get started:
QSplashScreen splash(":/images/splash.png"); splash.show(); app.processEvents(); QEventLoop loop; QTimer::singleShot(3000, &loop, &QEventLoop::quit); loop.exec(); QWidget widget; widget.show(); sps.finish(&widget); return app.exec();