IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)

QSystemTrayIcon Class

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

Article lu   fois.

L'auteur

Liens sociaux

Viadeo Twitter Facebook Share on Google+   

QSystemTrayIcon Class

  • Header: QSystemTrayIcon

  • CMake:

    find_package(Qt6 REQUIRED COMPONENTS Widgets)

    target_link_libraries(mytarget PRIVATE Qt6::Widgets)

  • qmake: QT += widgets

  • Inherits: QObject

  • Group: QSystemTrayIcon is part of desktop

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 system tray on Windows XP.

The QSystemTrayIcon class can be used on the following platforms:

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.

See Also

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.

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

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

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:

  • icon() const

  • void setIcon(const &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:

  • toolTip() const

  • void setToolTip(const &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)

Member Function Documentation

 

QSystemTrayIcon::QSystemTrayIcon(QObject *parent = nullptr)

Constructs a QSystemTrayIcon object with the given parent.

The icon is initially invisible.

See Also

See also visible

QSystemTrayIcon::QSystemTrayIcon(const QIcon &icon, QObject *parent = nullptr)

Constructs a QSystemTrayIcon object with the given icon and parent.

The icon is initially invisible.

See Also

See also visible

[virtual] QSystemTrayIcon::~QSystemTrayIcon()

Removes the icon from the system tray and frees all allocated resources.

void QSystemTrayIcon::activated(QSystemTrayIcon::ActivationReason reason)

This signal is emitted when the user activates the system tray icon. reason specifies the reason for activation. QSystemTrayIcon::ActivationReason enumerates the various reasons.

See Also

QMenu *QSystemTrayIcon::contextMenu() const

Returns the current context menu for the system tray entry.

See Also

See also setContextMenu()

[override virtual protected] bool QSystemTrayIcon::event(QEvent *e)

Reimplements: QObject::event(QEvent *e).

QRect QSystemTrayIcon::geometry() const

Returns the geometry of the system tray icon in screen coordinates.

See Also

See also visible

void QSystemTrayIcon::hide()

Hides the system tray entry.

See Also

See also show(), visible

[static] bool QSystemTrayIcon::isSystemTrayAvailable()

Returns true if the system tray is available; otherwise returns false.

If the system tray is currently unavailable but becomes available later, QSystemTrayIcon will automatically add an entry in the system tray if it is visible.

void QSystemTrayIcon::messageClicked()

This signal is emitted when the message displayed using showMessage() was clicked by the user.

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

See also activated()

void QSystemTrayIcon::setContextMenu(QMenu *menu)

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.

On macOS, this is currently converted to a NSMenu, so the aboutToHide() signal is not emitted.

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

See also contextMenu()

void QSystemTrayIcon::show()

Shows the icon in the system tray.

See Also

See also hide(), visible

void QSystemTrayIcon::showMessage(const QString &title, const QString &message, QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::Information, int millisecondsTimeoutHint = 10000)

Shows a balloon message for the entry with the given title, message and icon for the time specified in millisecondsTimeoutHint. title and message 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

See also show(), supportsMessages()

[since 5.9] void QSystemTrayIcon::showMessage(const QString &title, const QString &message, const QIcon &icon, int millisecondsTimeoutHint = 10000)

This function overloads showMessage().

Shows a balloon message for the entry with the given title, message, and custom icon icon for the time specified in millisecondsTimeoutHint.

This function was introduced in Qt 5.9.

[static] bool QSystemTrayIcon::supportsMessages()

Returns true if the system tray supports balloon messages; otherwise returns false.

See Also

See also showMessage()

Vous avez aimé ce tutoriel ? Alors partagez-le en cliquant sur les boutons suivants : Viadeo Twitter Facebook Share on Google+