Splash screen showing for two seconds
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:
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();
}
And define a slot in your main window called slInit (or whatever you want to call it) where you put the following code:
Code:
void mainWND::slInit()
{
setWindowOpacity(1);
}
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! :D
Re: Splash screen showing for two seconds
you can also add some comments during this time
Code:
pSplash->showMessage("Start ...");
pSplash->showMessage("Initialise the Database...");
replace "->" by "." in your case
Re: Splash screen showing for two seconds
to do what you have to create an header for main.h ?? isn't it?
oups forget it....
You added the call to the mainwindow. read it too quickly.
Re: Splash screen showing for two seconds
under my X11, the splashwindow comes with the mainwindow.
Here is the description in QWidget class
"This feature is available on Mac OS X, X11 platforms that support the Composite extension, and Windows 2000 and later.
Note that under X11 you need to have a composite manager running, and the X11 specific _NET_WM_WINDOW_OPACITY atom needs to be supported by the window manager you are using."
but you can simply change "w.setWindowOpacity(0);w.show();" to "w.hide()"
can redefine slinit function to "this->show()" and works as expected.
Quote:
Originally Posted by
Koas
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:
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();
}
And define a slot in your main window called slInit (or whatever you want to call it) where you put the following code:
Code:
void mainWND::slInit()
{
setWindowOpacity(1);
}
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! :D
Re: Splash screen showing for two seconds
thanks
I modified my splash screen
et voila working code below
Code:
int main(int argc, char *argv[]) {
a.connect(&a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );// added test for player
// The splash screen
pSplash
->setPixmap
(QPixmap(":images/Splash.png"));
pSplash->show();
pSplash->showMessage("Start ...");
// main window
MainWindow w;
w.
setWindowTitle(QObject::tr(" my title"));
w.hide();// mainwindow disappears
QTimer::singleShot(3000, pSplash,
SLOT(close
()));
// close splash after 4s QTimer::singleShot(3000,
&w,
SLOT(slInit
()));
// mainwindow reappears after 4s
// create DataBase.
pSplash->showMessage("Initialise the Database...");// shows comments
w.databaseobject-> createPlayListTables(); // DB created but need another object in mainwindow!!
pSplash->showMessage("load data...");
w.loadProgamListFromDB(); //load data to application
return a.exec();
}
also into the mainwindow....
....
void mainWND::slInit(){
this->show();
}
.......
thanks
pass the code around
Re: Splash screen showing for two seconds
Quote:
Originally Posted by
Sheng
but you can simply change "w.setWindowOpacity(0);w.show();" to "w.hide()"
can redefine slinit function to "this->show()" and works as expected.
Of course! How didn't I think of that! Maybe it's because I was playing with the setWindowOpacity() function and thought about the splash screen issue...
Anyway, the "hide() then show()" solution is much better, since we don't have to worry about the transparency issues (I think my first code wouldn't work well in Windows 98 for example).
I love these forums, everyday I learn something new! :)