-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
41 lines (29 loc) · 871 Bytes
/
main.cpp
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
31
32
33
34
35
36
37
38
39
40
41
#include "game.h"
#include <QDesktopWidget>
#include <QApplication>
#include <QPalette>
void center(QWidget &widget)
{
int x, y;
int screenWidth;
int screenHeight;
int WIDTH = 300;
int HEIGHT = 400;//set the size of the window
//set the color of background to be white
QDesktopWidget *desktop = QApplication::desktop();
screenWidth = desktop->width();
screenHeight = desktop->height();
x = (screenWidth - WIDTH)/2;
y = (screenHeight - HEIGHT)/2 ;
widget.setGeometry(x, y, WIDTH, HEIGHT);//to make the window appear in the middle of the screen
widget.setFixedSize(WIDTH, HEIGHT);
}
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
Game window;//create a window for the game
window.setWindowTitle("Game");//set the window's name to be "Game"
window.show();
center(window);
return app.exec();
}