QT4-系统托盘图标的使用(一)

系统托盘图标是一种很有用的提示方式,Qt作为一款强大的GUI设计工具自然不会在这个功能上缺席。

 

在qt4的demo中详细的记录了系统托盘图标的使用方法,经过实际的操作我也在自己的程序里使用了一把。在这里记录一下。

 

使用的类是QSystemTrayIcon(引用一下帮助文档里的介绍)

 

这里需要值得注意的是

 

The QSystemTrayIcon class can be used on the following platforms:

  • All supported versions of Windows.
  • All window managers for X11 that implement the freedesktop.org system tray specification, including recent versions of KDE and GNOME.
  • All supported versions of Mac OS X. Note that the Growl notification system must be installed forQSystemTrayIcon::showMessage() to display messages.

 

其他的详细内容可以通过帮助手册来查询。

 

使用的方法和步骤如下:

 

1、#include <QSystemTrayIcon>如果需要系统托盘图标的菜单,则还需要#include <QMenu>

2、声明对象QSystemTrayIcon *tray和QMenu *trayMenu;

3、接下来可以对tay进行一些初始化的工作(部分代码省略,可以参照手册)

 

 tray->setToolTip(...);//设置tooltip
 tray->setIcon(QIcon("..."));//设置显示的图标,这里QIcon类不需要单独声明

 tray->show();//在系统托盘显示图标,可以更具需要在适当时候显示图标

 

 

      到此,系统托盘图标已经可以成功的显示在系统托盘了,接下来可以用tray->showMessage来显示一些消息。

后面的内容再记录其他的一些功能。

The QSystemTrayIcon class provides an icon for an application in the system tray.

Modern operating systems usually provide a special area on the desktop, called the system tray or notification area, where long-running applications can display icons and short messages.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值