-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
66 lines (47 loc) · 1.64 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
57
58
59
60
61
62
63
64
65
66
#include <QApplication>
#include <QQmlApplicationEngine>
#include <QSystemTrayIcon>
#include <QPainter>
#include <QQuickWindow>
#include <QQmlContext>
#include <QMenu>
#include "systemtrayicon.h"
QSystemTrayIcon* createSystemTray(QAction*& showAction)
{
QPixmap px(64,64);
px.fill(Qt::transparent);
QPainter p(&px);
p.setPen(QPen(Qt::black, 4.0));
p.drawLine(0, 50, 16, 30);
p.drawLine(16, 30, 32, 20);
p.drawLine(32, 20, 48, 40);
p.drawLine(48, 40, 64, 10);
QIcon icon(px);
QSystemTrayIcon* systemTrayIcon = new SystemTrayIcon();
systemTrayIcon->setIcon(icon);
QMenu* systemTrayContextMenu = new QMenu();
showAction = systemTrayContextMenu->addAction("Show");
QAction* quitAction = systemTrayContextMenu->addAction("Quit");
QObject::connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
systemTrayIcon->setContextMenu(systemTrayContextMenu);
systemTrayIcon->show();
return systemTrayIcon;
}
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QApplication app(argc, argv);
qRegisterMetaType<QSystemTrayIcon::ActivationReason>("QSystemTrayIcon::ActivationReason");
QAction* showAction;
QSystemTrayIcon* systemTrayIcon = createSystemTray(showAction);
QQmlApplicationEngine engine;
engine.rootContext()->setContextProperty("ShowAction", showAction);
engine.rootContext()->setContextProperty("SystemTray", systemTrayIcon);
engine.load(QUrl(QLatin1String("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
return -1;
QQuickWindow* appWindow = qobject_cast<QQuickWindow*>(engine.rootObjects().first());
if(!appWindow)
return -1;
return app.exec();
}