• 大小: 129KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-06
  • 语言: 其他
  • 标签: 系统托盘  

资源简介

资源效果及讲解博客地址: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() {
    //判断系统是否支持系统托盘图标
    if (!QSystemTrayIcon::isSystemTrayAvailable()) {
#ifndef QT_NO_DEBUG
            QMessageBox::critical(nullptr
                   “警告““当前系统不支持系统托盘“);
#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()
{
    // 设置菜单图标
//    hideAction_->setIcon

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       4591  2017-02-10 16:32  系统托盘\customsystemtrayicon.cpp

     文件       2497  2017-02-20 11:53  系统托盘\customsystemtrayicon.h

     文件     150040  2017-02-20 11:44  系统托盘\系统托盘(CustomSystemTrayIcon).gif

     文件       7596  2017-02-10 16:24  系统托盘\系统托盘(CustomSystemTrayIcon).png

     文件       9570  2017-02-10 16:25  系统托盘\系统托盘菜单栏(CustomSystemTrayIcon).png

     目录          0  2017-02-20 11:51  系统托盘

----------- ---------  ---------- -----  ----

               174294                    6


评论

共有 条评论