Skip to content

Commit

Permalink
QMenu and click event
Browse files Browse the repository at this point in the history
  • Loading branch information
mhtvsSFrpHdE committed Aug 12, 2022
1 parent cf611e4 commit 6330f2c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
29 changes: 29 additions & 0 deletions qpp/prefetch/Source/Interface/tray_icon.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,43 @@
#include <QMenu>
#include <QAction>

#include "..\Global\global.h"
#include "..\Output\stdout.h"

QSystemTrayIcon *TrayIcon::systemTrayIcon = NULL;

void TrayIcon::init()
{
TrayIcon::systemTrayIcon = new QSystemTrayIcon(Global::qGuiApplication);

QMenu *qMenu = new QMenu();

QAction *pauseAction = new QAction("Pause", qMenu);
connect(pauseAction, SIGNAL(triggered()), this, SLOT(action_pause()));
qMenu->addAction(pauseAction);

QAction *resumeAction = new QAction("Resume", qMenu);
connect(resumeAction, SIGNAL(triggered()), this, SLOT(action_resume()));
qMenu->addAction(resumeAction);

systemTrayIcon->setContextMenu(qMenu);
}

void TrayIcon::start()
{
TrayIcon::systemTrayIcon->setIcon(QIcon(":/qrc/Resource/icon/main/prefetch.png"));
TrayIcon::systemTrayIcon->show();
}

void TrayIcon::action_pause()
{
*StdOut::consoleOutput << "Click pause"
<< endl;
StdOut::consoleOutput->flush();
}
void TrayIcon::action_resume()
{
*StdOut::consoleOutput << "Click resume"
<< endl;
StdOut::consoleOutput->flush();
}
4 changes: 4 additions & 0 deletions qpp/prefetch/Source/Interface/tray_icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ class TrayIcon : public QObject
// Show system tray icon
static void start();

public slots:
void action_pause();
void action_resume();

private:
static QSystemTrayIcon *systemTrayIcon;
};

0 comments on commit 6330f2c

Please sign in to comment.