-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.cpp
More file actions
30 lines (27 loc) · 797 Bytes
/
Copy pathmain.cpp
File metadata and controls
30 lines (27 loc) · 797 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "gui_main.h"
#include <QApplication>
//QDesktopWidget
#include <QDesktopWidget>
#include <QPoint>
QPoint get_window_center(int window_width, int window_height)
{
//获取桌面信息
QDesktopWidget *pDesktopWidget = QApplication::desktop();
//获取可用桌面大小
QRect DeskRect = pDesktopWidget->availableGeometry();
int new_width = (DeskRect.width() - window_width) / 2;
int new_height = (DeskRect.height() - window_height) / 2;
QPoint window_rect(new_width, new_height);
return window_rect;
}
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MainWindow_UI w;
//让窗口居中显示
QPoint window_center(0, 0);
window_center += get_window_center(w.width(), w.height());
w.move(window_center.x(), window_center.y());
w.show();
return a.exec();
}