代码拉取完成,页面将自动刷新
#include "trayicon.h"
#include "mainwindow.h"
#include <QMenu>
#include <QCoreApplication>
#include <QApplication>
#define App (static_cast<QApplication*>(QCoreApplication::instance()))
TrayIcon::TrayIcon(QObject *parent)
: QSystemTrayIcon(parent)
{
m_window = new MainWindow();
m_traymenu = new QMenu();
QAction *exitAction = new QAction(m_traymenu);
exitAction->setText("退出");
connect(exitAction, &QAction::triggered, this, &TrayIcon::quitApp);
QAction *setShowAction = new QAction(m_traymenu);
setShowAction->setText("显示");
connect(setShowAction, &QAction::triggered, this, [ = ] {
m_window->show();
m_window->activateWindow();
});
QAction *setHideAction = new QAction(m_traymenu);
setHideAction->setText("隐藏");
connect(setHideAction, &QAction::triggered, this, [ = ] {
this->hide();
});
m_traymenu->addAction(setShowAction);
m_traymenu->addAction(setHideAction);
m_traymenu->addAction(exitAction);
this->setContextMenu(m_traymenu);
connect(this, &QSystemTrayIcon::activated, this, [ = ](QSystemTrayIcon::ActivationReason reason) {
if (QSystemTrayIcon::Trigger == reason) {
m_window->show();
m_window->activateWindow();
}
});
m_window->show();
setIcon(QIcon(":/install/window.svg"));
}
TrayIcon::~TrayIcon()
{
delete m_window;
m_window = nullptr;
}
void TrayIcon::quitApp()
{
App->exit();
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。