Hi, I've searched for this and haven't found it, so I thought I'd share this little code.
If you want a dummy splash screen (that is, your main window can start immediately but you want the splash screen to stay a couple of seconds) you can use the following code:
#include <QtGui/QApplication>
#include <QSplashScreen>
#include "mainWND.h"
int main(int argc, char *argv[])
{
QPixmap pixmap
(":/mainWND/Resources/splash.png");
mainWND w;
w.setWindowOpacity(0);
w.show();
splash.show();
QTimer::singleShot(2000,
&splash,
SLOT(close
()));
QTimer::singleShot(2000,
&w,
SLOT(slInit
()));
return a.exec();
}
#include <QtGui/QApplication>
#include <QSplashScreen>
#include "mainWND.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QPixmap pixmap(":/mainWND/Resources/splash.png");
QSplashScreen splash(pixmap,Qt::WindowStaysOnTopHint);
mainWND w;
w.setWindowOpacity(0);
w.show();
splash.show();
QTimer::singleShot(2000, &splash, SLOT(close()));
QTimer::singleShot(2000, &w, SLOT(slInit()));
return a.exec();
}
To copy to clipboard, switch view to plain text mode
And define a slot in your main window called slInit (or whatever you want to call it) where you put the following code:
void mainWND::slInit()
{
setWindowOpacity(1);
}
void mainWND::slInit()
{
setWindowOpacity(1);
}
To copy to clipboard, switch view to plain text mode
With this trick you can show your splash screen for some seconds, then make your main window appear. I have only tested it in Windows Vista, any feedback for other platforms would be great.
I hope this helps anyone, this forum has been a great source of info for my Qt programming and I thought I should give something back!
Bookmarks