Qt托盘实现

来源:互联网 发布:slack是什么软件 编辑:程序博客网 时间:2024/05/17 07:04

实现比较简单, 值得注意的是在main函数中设置app.setQuitOnLastWindowClosed(false);

 

 

class WeatherTrayIcon : public QSystemTrayIcon{Q_OBJECTpublic:explicit WeatherTrayIcon(QObject *parent = NULL);~WeatherTrayIcon();private:private slots:void    SlotIconActivate(QSystemTrayIcon::ActivationReason reason);private:};


 

WeatherTrayIcon::WeatherTrayIcon(QObject *parent): QSystemTrayIcon(parent){setIcon(QIcon(":/WeatherTrayIcon/Resources/icon.jpg"));setToolTip("TurboAudit");connect(this, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(SlotIconActivate(QSystemTrayIcon::ActivationReason)));}WeatherTrayIcon::~WeatherTrayIcon(){}void WeatherTrayIcon::SlotIconActivate( QSystemTrayIcon::ActivationReason reason ){switch (reason){case QSystemTrayIcon::Trigger:case QSystemTrayIcon::DoubleClick:// 显示主窗体//w->show();break;case QSystemTrayIcon::Context:// 显示菜单{QRect rect = geometry();QRect menuRect;menuRect.setLeft(rect.right());menuRect.setTop(rect.y()-200);menuRect.setWidth(100);menuRect.setHeight(200);QWidget *w = new QWidget;w->setGeometry(menuRect);w->show();}break;default:;}}


 

原创粉丝点击