qt设置窗口在桌面居中显示

#include
#include
#include


int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow *win = new QMainWindow;
QDesktopWidget *desk = QApplication::desktop();
QRect deskRect = desk->availableGeometry();

// 显示窗口
win->show();

// 移动窗口
win->move((deskRect.width()-win->width())/2, (deskRect.height()-win->height())/2);

return app.exec();
}

你可能感兴趣的:(qt)