QSystemTrayIcon Class
The QSystemTrayIcon class provides an icon for an application in the system tray. More...
| Header: | #include <QSystemTrayIcon> |
| qmake: | QT += widgets |
| Since: | Qt 4.2 |
| Inherits: | QObject |
This class was introduced in Qt 4.2.
Public Types
| enum | ActivationReason { Unknown, Context, DoubleClick, Trigger, MiddleClick } |
| enum | MessageIcon { NoIcon, Information, Warning, Critical } |
Properties
Public Functions
| QIcon | icon() const |
| bool | isVisible() const |
| void | setIcon(const QIcon &icon) |
| void | setToolTip(const QString &tip) |
| QString | toolTip() const |
Public Slots
| void | setVisible(bool visible) |
Detailed Description
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.

The QSystemTrayIcon class can be used on the following platforms:
- All supported versions of Windows.
- All window managers and independent tray implementations for X11 that implement the http://standards.freedesktop.org/systemtray-spec/systemtray-spec-0.2.html freedesktop.org XEmbed system tray specification.
- All X11 desktop environments that implement the D-Bus http://www.freedesktop.org/wiki/Specifications/StatusNotifierItem/StatusNotifierItem specification, including recent versions of KDE and Unity.
- All supported versions of macOS.
To check whether a system tray is present on the user's desktop, call the QSystemTrayIcon::isSystemTrayAvailable() static function.
To add a system tray entry, create a QSystemTrayIcon object, call setContextMenu() to provide a context menu for the icon, and call show() to make it visible in the system tray. Status notification messages ("balloon messages") can be displayed at any time using showMessage().
If the system tray is unavailable when a system tray icon is constructed, but becomes available later, QSystemTrayIcon will automatically add an entry for the application in the system tray if the icon is visible.
The activated() signal is emitted when the user activates the icon.
Only on X11, when a tooltip is requested, the QSystemTrayIcon receives a QHelpEvent of type QEvent::ToolTip. Additionally, the QSystemTrayIcon receives wheel events of type QEvent::Wheel. These are not supported on any other platform. Note: Since GNOME Shell version 3.26, not all QSystemTrayIcon::ActivationReason are supported by the system without shell extensions installed.
See also QDesktopServices, QDesktopWidget, Desktop Integration, and System Tray Icon Example.
Member Type Documentation
enum QSystemTrayIcon::ActivationReason
This enum describes the reason the system tray was activated.
| Constant | Value | Description |
|---|---|---|
QSystemTrayIcon::Unknown | 0 | Unknown reason |
QSystemTrayIcon::Context | 1 | The context menu for the system tray entry was requested |
QSystemTrayIcon::DoubleClick | 2 | The system tray entry was double clicked. |
Note: On macOS, a double click will only be emitted if no context menu is set, since the menu opens on mouse press
| Constant | Value | Description |
|---|---|---|
QSystemTrayIcon::Trigger | 3 | The system tray entry was clicked |
QSystemTrayIcon::MiddleClick | 4 | The system tray entry was clicked with the middle mouse button |
See also activated().
enum QSystemTrayIcon::MessageIcon
This enum describes the icon that is shown when a balloon message is displayed.
| Constant | Value | Description |
|---|---|---|
QSystemTrayIcon::NoIcon | 0 | No icon is shown. |
QSystemTrayIcon::Information | 1 | An information icon is shown. |
QSystemTrayIcon::Warning | 2 | A standard warning icon is shown. |
QSystemTrayIcon::Critical | 3 | A critical warning icon is shown. |
See also QMessageBox.
Property Documentation
icon : QIcon
This property holds the system tray icon
On Windows, the system tray icon size is 16x16; on X11, the preferred size is 22x22. The icon will be scaled to the appropriate size as necessary.
Access functions:
| QIcon | icon() const |
| void | setIcon(const QIcon &icon) |
toolTip : QString
This property holds the tooltip for the system tray entry
On some systems, the tooltip's length is limited. The tooltip will be truncated if necessary.
Access functions:
| QString | toolTip() const |
| void | setToolTip(const QString &tip) |
visible : bool
This property holds whether the system tray entry is visible
Setting this property to true or calling show() makes the system tray icon visible; setting this property to false or calling hide() hides it.
Access functions:
| bool | isVisible() const |
| void | setVisible(bool visible) |