File indexing completed on 2024-05-05 14:09:18
0001 #include <QAction> 0002 #include <QActionGroup> 0003 #include <QApplication> 0004 #include <QMenu> 0005 #include <QSystemTrayIcon> 0006 0007 int main(int argc, char *argv[]) 0008 { 0009 QApplication app(argc, argv); 0010 0011 QSystemTrayIcon trayIcon(QIcon::fromTheme(QStringLiteral("application-exit"))); 0012 0013 QMenu contextMenu; 0014 0015 QAction *action1 = contextMenu.addAction(QStringLiteral("Exclusive Item 1")); 0016 QAction *action2 = contextMenu.addAction(QStringLiteral("Exclusive Item 2")); 0017 action1->setCheckable(true); 0018 action1->setChecked(true); 0019 action2->setCheckable(true); 0020 0021 QActionGroup *actionGroup = new QActionGroup(&contextMenu); 0022 actionGroup->addAction(action1); 0023 actionGroup->addAction(action2); 0024 0025 QAction quitAction(QIcon::fromTheme(QStringLiteral("application-exit")), QStringLiteral("Quit")); 0026 QObject::connect(&quitAction, &QAction::triggered, &app, &QApplication::quit); 0027 contextMenu.addAction(&quitAction); 0028 0029 trayIcon.setContextMenu(&contextMenu); 0030 trayIcon.show(); 0031 0032 return app.exec(); 0033 }