Search code examples
c++qtcenteringqsplashscreen

Why is QSplashScreen not centered when shown?


I create a QSplashScreen in the constructor of a QMainWindow:

MainApp::MainApp() : QMainWindow(),
    splashScreen(new QSplashScreen)
{
    splashScreen->setFixedSize(350, 120);
    //splashScreen->move(splashScreen->x()-175, splashScreen->y()-60); //inits with upperleft corner at screen center
    splashScreen->setWindowOpacity(0.85);
    splashScreen->setAttribute(Qt::WA_StyledBackground);
    splashScreen->setStyleSheet("QSplashScreen { background-color: #000;"
                                                "background-image: url('"+pathLogo+"');"
                                                "background-repeat: no-repeat;"
                                                "background-position: center;"
                                                "border: 2px solid #fac805; }");

        QLabel *vrsLbl = new QLabel(splashScreen);
        vrsLbl->resize(350, 13);
        vrsLbl->move(0, 80);
        vrsLbl->setPixmap(pxVersion);
        vrsLbl->setAlignment(Qt::AlignHCenter);

    splashScreen->show();
}

The splashscreen is shown with its upperleft corner at the center of the screen. The easy workaround is to move it (since its size is known), as commented out above.

According to the docs:

The splash screen appears in the center of the screen.

So what's going wrong here?


Solution

  • I may have been a bit too quick to post this as a question.

    After some testing I figured out that apparently a QSplashScreen doesn't center when it has an empty QPixmap.