-
大小: 129KB文件類型: .rar金幣: 2下載: 0 次發(fā)布日期: 2021-05-06
- 語言: 其他
- 標(biāo)簽: 系統(tǒng)托盤??
資源簡介
資源效果及講解博客地址:http://blog.csdn.net/csnd_ayo/article/details/56004234

代碼片段和文件信息
#include?
#include?
#include?
#include?
#ifndef?QT_NO_DEBUG
#include?
#endif
#include?“customsystemtrayicon.h“
CustomSystemTrayIcon*?CustomSystemTrayIcon::self_?=?nullptr;
CustomSystemTrayIcon::CustomSystemTrayIcon(QWidget?*parent)
????:?QWidget(parent)?{
????init();
}
void?CustomSystemTrayIcon::setTray(const?QString?&_name
???????????????????????????????????const?QString?&_icon
???????????????????????????????????const?QString?&_describe)?{
????setTray(_name_icon);
????trayDescribe_?=?_describe;
}
void?CustomSystemTrayIcon::setTray(const?QString?&_name
???????????????????????????????????const?QString?&_icon)?{
????setTray(_name);
????trayobject_->setIcon(QIcon(_icon));
}
void?CustomSystemTrayIcon::setTray(const?QString?&_name)?{
????trayobject_->setToolTip(_name);
}
void?CustomSystemTrayIcon::showTray()
{
????trayobject_->show();
????trayobject_->showMessage(trayobject_->toolTip()trayDescribe_
????????????????????????????QSystemTrayIcon::Information?5000);
}
void?CustomSystemTrayIcon::hideTray()
{
????trayobject_->hide();
}
CustomSystemTrayIcon*?CustomSystemTrayIcon::instance(QWidget?*_this)
{
????if?(self_?==?nullptr)?{
????????if?(_this?!=?nullptr)?{
????????????self_?=?new?CustomSystemTrayIcon(_this);
????????}
????????else?{
#ifndef?QT_NO_DEBUG
????????????QMessageBox::critical(nullptr
???????????????????“警告““不符合要求的托盤操作代碼“);
#endif
????????????return?nullptr;
????????}
????}
????return?self_;
}
void?CustomSystemTrayIcon::trayActivatedEvent(
????????QSystemTrayIcon::ActivationReason?_action)?{
????switch(_action)
????{
????case?QSystemTrayIcon::Unknown:
????????trayobject_->showMessage(trayobject_->toolTip()trayDescribe_
????????????????????????????????QSystemTrayIcon::Information?5000);
????????break;
????//?右鍵單擊
????case?QSystemTrayIcon::Context:
????????break;
????//?點擊
????case?QSystemTrayIcon::Trigger:
????????break;
????//?雙擊
????case?QSystemTrayIcon::DoubleClick:
????????this->parentWidget()->showNormal();
????????break;
????//?中鍵點擊
????case?QSystemTrayIcon::MiddleClick:
????????this->parentWidget()->hide();
????????break;
????default:
????????break;
????}
}
void?CustomSystemTrayIcon::init()?{
????//判斷系統(tǒng)是否支持系統(tǒng)托盤圖標(biāo)
????if?(!QSystemTrayIcon::isSystemTrayAvailable())?{
#ifndef?QT_NO_DEBUG
????????????QMessageBox::critical(nullptr
???????????????????“警告““當(dāng)前系統(tǒng)不支持系統(tǒng)托盤“);
#endif
????????return;
????}
????//?托盤對象
????trayobject_?=?new?QSystemTrayIcon(this);
????//?隱藏按鈕(菜單)
????hideAction_?=?new?QAction(“隱?藏(&Z)“this);
????//?還原按鈕(菜單)
????restoreAction_?=?new?QAction(“還?原(&X)“this);
????//?退出按鈕(菜單)
????quitAction_?=?new?QAction(“退?出(&C)“this);
????//?根菜單
????menu_?=?new?QMenu((QWidget*)QApplication::desktop());
????initMenu();
????initTray();
????initSignal();
}
void?CustomSystemTrayIcon::initMenu()
{
????//?設(shè)置菜單圖標(biāo)
//????hideAction_->setIcon
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4591??2017-02-10?16:32??系統(tǒng)托盤\customsystemtrayicon.cpp
?????文件???????2497??2017-02-20?11:53??系統(tǒng)托盤\customsystemtrayicon.h
?????文件?????150040??2017-02-20?11:44??系統(tǒng)托盤\系統(tǒng)托盤(CustomSystemTrayIcon).gif
?????文件???????7596??2017-02-10?16:24??系統(tǒng)托盤\系統(tǒng)托盤(CustomSystemTrayIcon).png
?????文件???????9570??2017-02-10?16:25??系統(tǒng)托盤\系統(tǒng)托盤菜單欄(CustomSystemTrayIcon).png
?????目錄??????????0??2017-02-20?11:51??系統(tǒng)托盤
-----------?---------??----------?-----??----
???????????????174294????????????????????6
評論
共有 條評論