1 Star 2 Fork 0

depend/x11opacitytool

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
trayicon.cpp 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
depend 提交于 2021-04-09 13:40 . fix: first commit
#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();
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/liuminghang/x11opacitytool.git
git@gitee.com:liuminghang/x11opacitytool.git
liuminghang
x11opacitytool
x11opacitytool
master

搜索帮助