托盤圖標,一個自己腦子出現很久的詞,可惜自己都沒動手去實現。最近看見的,聽見的多了,自己也感興趣就弄弄了,感覺還蠻簡單了。
貼出效果圖:
那麼多功能,其實就一個類就搞定了,那就是QSystemTrayIcon
頭文件(主要 1.聲明菜單相關動作 2.聲明系統托盤對象,以及相關托盤槽函數 3.關閉事件)
- #ifndef SYSTEMTRAYICON_H
- #define SYSTEMTRAYICON_H
-
- #include <QMainWindow>
- #include <QMenu>
- #include <QSystemTrayIcon>
- #include <QCloseEvent>
- namespace Ui {
- class SystemTrayIcon;
- }
-
- class SystemTrayIcon : public QMainWindow
- {
- Q_OBJECT
-
- public:
- explicit SystemTrayIcon(QWidget *parent = 0);
- ~SystemTrayIcon();
-
- void CreatTrayMenu();
- void CreatTrayIcon();
-
- QSystemTrayIcon *myTrayIcon;
-
- QMenu *myMenu;
-
- QAction *miniSizeAction;
- QAction *maxSizeAction;
- QAction *restoreWinAction;
- QAction *quitAction;
-
- private:
- Ui::SystemTrayIcon *ui;
-
- public slots:
- void iconActivated(QSystemTrayIcon::ActivationReason reason);
-
- protected:
- void closeEvent(QCloseEvent *event);
-
- };
-
- #endif // SYSTEMTRAYICON_H