-
Notifications
You must be signed in to change notification settings - Fork 51
/
main.cpp
56 lines (40 loc) · 1.53 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <QApplication>
#ifdef _WIN32
#include "QWinWidget.h"
#else
#include "widget.h"
#endif
#ifdef __APPLE__
#include "OSXHideTitleBar.h"
#endif
int main(int argc, char *argv[])
{
//This has the app draw at HiDPI scaling on HiDPI displays, usually two pixels for every one logical pixel
QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
//This has QPixmap images use the @2x images when available
//See this bug for more details on how to get this right: https://bugreports.qt.io/browse/QTBUG-44486#comment-327410
QApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QApplication app(argc, argv);
//A common feature is to save your app's geometry on close such that you can draw in the same place on relaunch
//Thus this project supports specifying the X/Y/Width/Height in a cross-platform manner
int windowXPos, windowYPos, windowWidth, windowHeight;
windowXPos = 100;
windowYPos = 100;
windowWidth = 1024;
windowHeight = 768;
#ifdef _WIN32
//On Windows, the widget needs to be encapsulated in a native window for frameless rendering
//In this case, QWinWidget #includes "Widget.h", creates it, and adds it to a layout
QWinWidget w;
#else
//On OS X / Linux, the widget can handle everything itself so just create Widget as normal
Widget w;
#endif
#ifdef __APPLE__
//Then, hide the OS X title bar
OSXHideTitleBar::HideTitleBar(w.winId());
#endif
w.setGeometry(windowXPos, windowYPos, windowWidth, windowHeight);
w.show();
return app.exec();
}