Results 1 to 20 of 28

Thread: Splash Screen

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Splash Screen

    Hi. I've got a question. In C++ GUI Programming with Qt 4 is explained how to do a splash screen, but it's different than this, what I wanna do. In book it was explained how to do this when you were implementing forms manually, and I was doing forms by designer. And I want to display splash screen without for example "loading plugins", but only and image, which is displaying for 4 seconds, and after it main window is shown. How can I do that, on my main.cpp file:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlastiqueStyle>
    3. #include "maker.h"
    4. #include "about.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication::setStyle ( new QPlastiqueStyle() );
    9. QApplication app(argc, argv);
    10. MainWindow MainWindow;
    11. MainWindow.show();
    12. return app.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    Regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Splash Screen

    Create the splashscreen, show it, start a timer and when it timeouts, close it. Take a look at QSplashScreen docs to see some examples.

  3. #3
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    But the examples in docs doesn't say how to set timer

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Splash Screen

    Because they are not meant to close after 4 seconds Try reading the docs of a class that has a "timer" word in its name...

  5. #5
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    Quote Originally Posted by wysota View Post
    Because they are not meant to close after 4 seconds Try reading the docs of a class that has a "timer" word in its name...
    I mean to close not application, but spalsh. I've done everything what's described in docs (without timer, yet)
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlastiqueStyle>
    3. #include <QSplashScreen>
    4. #include "maker.h"
    5. #include "about.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication::setStyle ( new QPlastiqueStyle() );
    10. QApplication app(argc, argv);
    11. QPixmap pixmap("new/prefix1/Poker.jpg");
    12. QSplashScreen splash(pixmap);
    13. splash.show();
    14. app.processEvents();
    15.  
    16. MainWindow MainWindow;
    17. MainWindow.show();
    18. splash.finish(&MainWindow);
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 
    But when I run the program, splash screen doesn't appear. Regards

  6. #6
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Maybe you have a problem with the jpeg plugin. I have seen a few people getting this problem. Try using a PNG image instead.

    As for the timer, do something like this in main after you create the splash:
    Qt Code:
    1. QTimer splashTimer();
    2. splashTimer.setSingleShot( true );
    3. splashTimer.setInterval( 4000 ); //4 seconds
    4. connect( &splashTimer, SIGNAL( timeOut() ), &splash, SLOT( close() );
    5. splashTimer.start();
    To copy to clipboard, switch view to plain text mode 

    Regards

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Splash Screen

    Because you close it immediately. Splash screen is usually meant to occupy user's attention when the application takes time to initialize itself. If you only want to show the splashscreen because of eye candy, show the splash, start the timer and close it when the timer timeouts.

  8. #8
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    Marcel - i use jpg images for actions, and I works correctly.
    [B][/WysotaB] - yes, I want to use it as "eye candy". What do you mean that I close the app immediatly? Splash screen is waiting for my answer, isn't it?

  9. #9
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Understood.

    QSpkashScreen::finish:
    Makes the splash screen wait until the widget mainWin is displayed before calling close() on itself.
    This doesn't necessarily mean that you have time to see the splash.
    The main window may become visible very quickly, depending on what it contains, what initialization code you have and on the performance of your computer.

    Use the timer to make it stay visible for a predefined period of time.

    Regards

  10. #10
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    I've done this:
    Qt Code:
    1. #include <QApplication>
    2. #include <QPlastiqueStyle>
    3. #include <QSplashScreen>
    4. #include "maker.h"
    5. #include "about.h"
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication::setStyle ( new QPlastiqueStyle() );
    10. QApplication app(argc, argv);
    11. QPixmap pixmap("new/prefix1/Poker.jpg");
    12. QSplashScreen splash(pixmap);
    13.  
    14.  
    15. QTimer splashTimer();
    16.  
    17. splashTimer.setSingleShot( true );
    18.  
    19. splashTimer.setInterval( 4000 ); //4 seconds
    20.  
    21. connect( &splashTimer, SIGNAL( timeOut() ), &splash, SLOT( close() );
    22. splashTimer.start();
    23. splash.show();
    24.  
    25. MainWindow MainWindow;
    26. MainWindow.show();
    27. splash.finish(&MainWindow);
    28. return app.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 
    As you told me, but there appear errors:
    http://allyoucanupload.webshots.com/...25593906661174
    What's wrong with this code? It should show splash screen for 4 seconds, and after this time if should start application, right?

  11. #11
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Splash Screen

    Make sure you include <QTimer>.
    Also remove splash.finish() because now the splash closes when the timer time outs.

    The behavior is not as you describe it.
    The splash will stay visible for 4 seconds but in the mean time the main window may become visible. The splash does not block the main window.

    Regards

  12. #12
    Join Date
    May 2007
    Posts
    315
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Splash Screen

    The bahavior is exactly the same what I want it to be. I included QTimer, but errors are still the same:
    http://allyoucanupload.webshots.com/...25593906661174
    Regards

Similar Threads

  1. Problem with Splash Screen ?
    By vinod in forum Qt Programming
    Replies: 13
    Last Post: 11th April 2020, 18:15
  2. multi screen
    By Thomas Feldman in forum Qt Programming
    Replies: 5
    Last Post: 9th May 2007, 17:41
  3. QTimer based Splash Screen
    By bpetty in forum Newbie
    Replies: 6
    Last Post: 15th December 2006, 01:51
  4. Replies: 3
    Last Post: 8th December 2006, 19:51
  5. Problem with screen update...
    By mysearch05 in forum Qt Programming
    Replies: 2
    Last Post: 27th January 2006, 19:24

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.