[Interest] Getting keypresses in a splashscreen on OSX

Glenn Ramsey gr at componic.co.nz
Thu May 15 00:20:57 CEST 2014


Hi,

I am trying to get keypresses from QSplashScreen before my main window opens. My 
splash class inherits from QSplashScreen and overrides the keyPressEvent method.

The code below works on Windows but on OSX the keypresses are not intercepted 
until the main window opens.

Is there a workaround for this?

Glenn

splash.cpp:

...

void Splash::keyPressEvent(QKeyEvent *evt)
{
     std::cout << evt->text().toStdString() << std::endl;
}

main.cpp:

...

void delay(float seconds)
{
     QTime dieTime= QTime::currentTime().addSecs(seconds);
     while( QTime::currentTime() < dieTime )
         QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}

int main(int argc, char *argv[])
{
     QApplication a(argc, argv);

     Splash *splash = new Splash;
     splash->setPixmap(QPixmap(":/images/splash_loading.png"));
     splash->show();
     splash->grabKeyboard();

     // on OSX no keypresses captured here, on Windows keypresses captured
     delay(5.f);

     MainWindow w;
     w.show();

     // keypresses captured here on OSX and Windows
     delay(5.f);

     splash->releaseKeyboard();
     splash ->hide();

     return a.exec();
}



More information about the Interest mailing list