1. #include <QDesktopWidget>
    2. // 主屏幕居中显示
    3. QDesktopWidget* desktop = QApplication::desktop();
    4. QWidget* mainScreen = desktop->screen(0);
    5. move((mainScreen->width() - this->width()) / 2, (mainScreen->height() - this->height()) / 2); // this 是要显示的窗口的指针.