QT主窗体在屏幕居中显示

来源:互联网 发布:软件定制沟通 编辑:程序博客网 时间:2024/05/22 06:44

#include <QtGui/QtGui>

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

    //让窗体居中显示

    QDesktopWidget* desktop = QApplication::desktop();
    int width = desktop->availableGeometry(-1).width();
    int height = desktop->availableGeometry(-1).height();


    win.move((width - win.width())/2, (height - win.height())/2);
    win.show();

    return app.exec();
}