Search code examples
c++qtsplash-screenqsplashscreen

How to add widget to QSplashScreen after initial show()?


So my intended program flow is this:

  1. Create, show() QSplashScreen instance.
  2. Initialize other parts of system, including i18n module
  3. Add (translated) copyright notice (QLabel) to QSplashScreen instance.

The problem is that unless I hide() the splash screen, call QApplication::processEvents, add the QLabel, and then re-show() the splash screen--causing a huge flicker obviously--the QLabel doesn't render.

That is, I do not see the notice if I merely write this:

QLabel* pSplashNotice = new QLabel( mpSplashScreen );
pSplashNotice->setObjectName( "SplashNotice" );
pSplashNotice->setWordWrap( true );
pSplashNotice->setText( Localize(my_text) );
pSplashNotice->resize( 1200, 50 );
pSplashNotice->move( 100, 1000 );

mpSplashScreen->raise();
mpSplashScreen->show();

I have to precede the above by

mpSplashScreen->hide();
QApplication::processEvents(QEventLoop::AllEvents);

How can I get pSplashNotice to render without having to hide the splash screen?


Solution

  • You should add following call

    pSplashNotice->show();