代码之家  ›  专栏  ›  技术社区  ›  bur

为什么显示时QSplashScreen不居中?

  •  1
  • bur  · 技术社区  · 6 年前

    QSplashScreen 在一个 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 docs :

    1 回复  |  直到 6 年前
        1
  •  3
  •   bur    6 年前

    我可能是有点太快了,把这个作为一个问题。

    经过一番测试我发现 QSplashScreen 当它有一个空的 QPixmap