QSystemTrayIcon类为应用程序在系统托盘中提供一个图标。
其他就如代码所说,所有注释都有
mainwindow.h如下
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QTimer>
#include <QMenu>
#include <QMainWindow>
#include <QCloseEvent>
#include <QSystemTrayIcon>
class trayIconMenu;
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);
~MainWindow();
private slots:
void slot_iconIsActived(QSystemTrayIcon::ActivationReason);
void slot_quitApp();
void slot_testApp1();
void slot_testApp2();
void slot_testApp3();
void slot_changeIcon();
protected:
virtual void closeEvent(QCloseEvent *);
private:
Ui::MainWindow *ui;
QTimer *blink_timer;
trayIconMenu *m_traymenu;
QSystemTrayIcon * system_tray;
};
class trayIconMenu : public QMenu
{
Q_OBJECT
public:
trayIconMenu(QWidget*parent=nullptr);
void init_level