- class QSystemTrayIcon¶
The
QSystemTrayIcon
class provides an icon for an application in the system tray. More…Synopsis¶
Properties¶
Methods¶
def
__init__()
def
contextMenu()
def
geometry()
def
icon()
def
isVisible()
def
setContextMenu()
def
setIcon()
def
setToolTip()
def
toolTip()
Slots¶
def
hide()
def
setVisible()
def
show()
def
showMessage()
Signals¶
def
activated()
def
messageClicked()
Static functions¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
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 Linux desktop environments that implement the D-Bus StatusNotifierItem specification , including KDE, Gnome, Xfce, LXQt, and DDE.
All window managers and independent tray implementations for X11 that implement the freedesktop.org XEmbed system tray specification .
All supported versions of macOS.
To check whether a system tray is present on the user’s desktop, call the
isSystemTrayAvailable()
static function.To add a system tray entry, create a
QSystemTrayIcon
object, callsetContextMenu()
to provide a context menu for the icon, and callshow()
to make it visible in the system tray. Status notification messages (“balloon messages”) can be displayed at any time usingshowMessage()
.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 isvisible
.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, theQSystemTrayIcon
receives wheel events of type QEvent::Wheel. These are not supported on any other platform. Note: Since GNOME Shell version 3.26, not allActivationReason
are supported by the system without shell extensions installed.See also
System Tray Icon Example
- class ActivationReason¶
This enum describes the reason the system tray was activated.
Constant
Description
QSystemTrayIcon.Unknown
Unknown reason
QSystemTrayIcon.Context
The context menu for the system tray entry was requested
QSystemTrayIcon.DoubleClick
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
Description
QSystemTrayIcon.Trigger
The system tray entry was clicked
QSystemTrayIcon.MiddleClick
The system tray entry was clicked with the middle mouse button
See also
- class MessageIcon¶
This enum describes the icon that is shown when a balloon message is displayed.
Constant
Description
QSystemTrayIcon.NoIcon
No icon is shown.
QSystemTrayIcon.Information
An information icon is shown.
QSystemTrayIcon.Warning
A standard warning icon is shown.
QSystemTrayIcon.Critical
A critical warning icon is shown.
See also
Note
Properties can be used directly when
from __feature__ import true_property
is used or via accessor functions otherwise.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.
- property toolTipᅟ: str¶
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:
- property 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 callinghide()
hides it.- Access functions:
Constructs a
QSystemTrayIcon
object with the givenparent
.The icon is initially invisible.
See also
visible
Constructs a
QSystemTrayIcon
object with the givenicon
andparent
.The icon is initially invisible.
See also
visible
- activated(reason)¶
- Parameters:
reason –
ActivationReason
This signal is emitted when the user activates the system tray icon.
reason
specifies the reason for activation.ActivationReason
enumerates the various reasons.See also
Returns the current context menu for the system tray entry.
See also
Returns the geometry of the system tray icon in screen coordinates.
See also
visible
- hide()¶
Hides the system tray entry.
See also
show()
visible
Getter of property
iconᅟ
.- static isSystemTrayAvailable()¶
- Return type:
bool
Returns
true
if the system tray is available; otherwise returnsfalse
.If the system tray is currently unavailable but becomes available later,
QSystemTrayIcon
will automatically add an entry in the system tray if it isvisible
.- isVisible()¶
- Return type:
bool
Getter of property
visibleᅟ
.- messageClicked()¶
This signal is emitted when the message displayed using
showMessage()
was clicked by the user.Note
We follow Microsoft Windows behavior, so the signal is also emitted when the user clicks on a tray icon with a balloon message displayed.
See also
Sets the specified
menu
to be the context menu for the system tray icon.The menu will pop up when the user requests the context menu for the system tray icon by clicking the mouse button.
Note
The system tray icon does not take ownership of the menu. You must ensure that it is deleted at the appropriate time by, for example, creating the menu with a suitable parent object.
See also
Setter of property
iconᅟ
.Setter of property
toolTipᅟ
.- setVisible(visible)¶
- Parameters:
visible – bool
See also
Setter of property
visibleᅟ
.- show()¶
Shows the icon in the system tray.
See also
hide()
visible
- showMessage(title, msg[, icon=QSystemTrayIcon.Information[, msecs=10000]])¶
- Parameters:
title – str
msg – str
icon –
MessageIcon
msecs – int
Shows a balloon message for the entry with the given
title
,message
andicon
for the time specified inmillisecondsTimeoutHint
.title
andmessage
must be plain text strings.Message can be clicked by the user; the
messageClicked()
signal will emitted when this occurs.Note that display of messages are dependent on the system configuration and user preferences, and that messages may not appear at all. Hence, it should not be relied upon as the sole means for providing critical information.
On Windows, the
millisecondsTimeoutHint
is usually ignored by the system when the application has focus.Has been turned into a slot in Qt 5.2.
See also
- showMessage(title, msg, icon[, msecs=10000])
- Parameters:
title – str
msg – str
icon –
QIcon
msecs – int
This function overloads
showMessage()
.Shows a balloon message for the entry with the given
title
,message
, and custom iconicon
for the time specified inmillisecondsTimeoutHint
.- static supportsMessages()¶
- Return type:
bool
Returns
true
if the system tray supports balloon messages; otherwise returnsfalse
.See also
- toolTip()¶
- Return type:
str
See also
Getter of property
toolTipᅟ
.