qt設定視窗在桌面居中顯示

生醃瀨尿蝦發表於2014-11-30
#include <QApplication>
#include <QMainWindow>
#include <QDesktopWidget>


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();
}

相關文章