QSystemTrayIcon类学习
来源:互联网 发布:阿里云搭建游戏加速器 编辑:程序博客网 时间:2024/05/16 13:38
代码来自“QT小神童”视频
#ifndef WIDGET_H
#define WIDGET_H
#include <QtGui/QWidget>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QLabel>
#include <QPixmap>
#include <QApplication>
#include <QDesktopWidget>
#include <QList>
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
~Widget();
protected slots:
void flash();
void handle(QSystemTrayIcon::ActivationReason);
void showPic();
private:
QSystemTrayIcon *sysIcon;
bool flag;
QTimer *timer2;
QLabel *label;
QList<QLabel *> list;
int i;
int j;
};
#endif // WIDGET_H
实现文件
#include "widget.h"
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
flag=0;
i=0;
j=0;
sysIcon=new QSystemTrayIcon;
// sysIcon->setIcon(QIcon(":/heart.png"));
sysIcon->show();
connect(sysIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this,SLOT(handle(QSystemTrayIcon::ActivationReason)));
QTimer *timer1=new QTimer(this);
timer1->start(500);
connect(timer1,SIGNAL(timeout()),this,SLOT(flash()));
timer2=new QTimer(this);
connect(timer2,SIGNAL(timeout()),this,SLOT(showPic()));
}
Widget::~Widget()
{
}
void Widget::flash()
{
switch(flag)
{
case 0:{sysIcon->setIcon(QIcon(":/heart.png"));
flag=1;
break;
}
case 1:{sysIcon->setIcon(QIcon(":/123.png"));
flag=0;
break;
}
}
}
void Widget::handle(QSystemTrayIcon::ActivationReason reason)
{
switch(reason)
{
case QSystemTrayIcon::DoubleClick:
timer2->start(1000);
}
}
void Widget::showPic()
{
label=new QLabel;
label->setWindowFlags(Qt::FramelessWindowHint|Qt::SubWindow);
label->setAttribute(Qt::WA_DeleteOnClose);
QPixmap pix(":/heart.png");
label->setPixmap(pix);
label->resize(pix.rect().width(),pix.rect().height());
if(i*label->width()>QApplication::desktop()->screenGeometry().width())
{
i=0;
j++;
}
if((j+1)*label->height()>QApplication::desktop()->screenGeometry().height())
{
j=0;
for(int count=0;count< list.size();count++)
list[count]->close();
list.clear();
}
list.append(label);
label->setGeometry(0+i*label->width(),0+j*label->height(),label->width(),label->height());
label->show();
i++;
}
主程序文件
#include <QtGui/QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
资源文件
- QSystemTrayIcon类学习
- QT 托盘类QSystemTrayIcon
- QSystemTrayIcon
- QSystemTrayIcon
- Two problems with QSystemTrayIcon
- QT中QSystemTrayIcon
- Qt之QSystemTrayIcon
- Qt之QSystemTrayIcon
- 窗体部件之QSystemTrayIcon
- QSystemTrayIcon 系统托盘使用总结
- QSystemTrayIcon menu无法消失问题
- QSystemTrayIcon增加系统托盘图标Demo
- Qt之系统托盘(QSystemTrayIcon详解)
- Qt之系统托盘(QSystemTrayIcon详解)
- Qt之系统托盘(QSystemTrayIcon详解)
- Qt浅谈之三十系统托盘(QSystemTrayIcon)
- Qt之系统托盘(QSystemTrayIcon详解)
- Qt5—系统托盘QSystemTrayIcon [2013-10-18整理]
- SIP RFC 3261
- oracle 数据库学习指导(1)
- 在Linux下,禁止某一个显示屏的输出
- Java靠强大的JVM维护了一个蓝领级语言?
- 线性查找与二分查找(java实现)
- QSystemTrayIcon类学习
- SVN服务器配置说明
- 毕业了,我们干什么?
- org.springframework.orm.hibernate3.HibernateSystemException: a different object with the same identi
- 二叉树的链表实现
- 用javascript 创建ActiveX对象时出现:Automation server can't create object"(Automation 服务器不能创建对). 错误的解决办法
- debian学习笔记6,终端下打开图形操作界面,安装常用软件
- Windows打印
- 想象五年之后的你