CopperSpice API  1.9.1
QSystemTrayIcon Class Reference

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

Inheritance diagram for QSystemTrayIcon:
QObject

Public Types

enum  ActivationReason
 
enum  MessageIcon
 

Public Signals

void activated (QSystemTrayIcon::ActivationReason reason)
 
void messageClicked ()
 
- Public Signals inherited from QObject
void destroyed (QObject *obj=nullptr)
 
void objectNameChanged (const QString &objectName)
 

Public Slots

void hide ()
 
void setVisible (bool visible)
 
void show ()
 
void showMessage (const QString &title, const QString &msg, QSystemTrayIcon::MessageIcon icon=QSystemTrayIcon::Information, int msecs=10000)
 
- Public Slots inherited from QObject
void deleteLater ()
 

Public Methods

 QSystemTrayIcon (const QIcon &icon, QObject *parent=nullptr)
 
 QSystemTrayIcon (QObject *parent=nullptr)
 
 ~QSystemTrayIcon ()
 
QMenucontextMenu () const
 
QRect geometry () const
 
QIcon icon () const
 
bool isVisible () const
 
void setContextMenu (QMenu *menu)
 
void setIcon (const QIcon &icon)
 
void setToolTip (const QString &tip)
 
QString toolTip () const
 
- Public Methods inherited from QObject
 QObject (QObject *parent=nullptr)
 
 ~QObject ()
 
bool blockSignals (bool block)
 
const QList< QObject * > & children () const
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
bool disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
bool disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const
 
void dumpObjectInfo ()
 
void dumpObjectTree ()
 
QList< QStringdynamicPropertyNames () const
 
virtual bool eventFilter (QObject *watched, QEvent *event)
 
template<typename T >
findChild (const QString &childName=QString ()) const
 
template<class T >
QList< T > findChildren (const QRegularExpression &regExp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
template<class T >
QList< T > findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const
 
bool inherits (const QString &className) const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const
 
bool isWindowType () const
 
void killTimer (int id)
 
const QMetaObjectmetaObject () const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const
 
QObject * parent () const
 
template<class T = QVariant>
property (const QString &name) const
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const QString &name, const QVariant &value)
 
bool signalsBlocked () const
 
int startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer)
 
QThreadthread () const
 

Static Public Methods

static bool isSystemTrayAvailable ()
 
static bool supportsMessages ()
 
- Static Public Methods inherited from QObject
static bool connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ())
 
static bool connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod)
 
static bool disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...))
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr)
 
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T >
static bool disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod)
 
static QMetaObjectstaticMetaObject ()
 
static QString tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >())
 

Protected Methods

bool event (QEvent *event) override
 
- Protected Methods inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signalMethod) const
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signalMethod) const
 
bool isSignalConnected (const QMetaMethod &signalMethod) const
 
int receivers (const QString &signal) const
 
QObject * sender () const
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *event)
 

Properties

 icon
 
 toolTip
 
 visible
 
- Properties inherited from QObject
 objectName
 

Additional Inherited Members

Detailed Description

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. The activated() signal is emitted when the user activates the icon.

The system tray on Windows XP.

The QSystemTrayIcon class can be used on the following platforms.

  • All supported versions of Windows
  • All window managers for X11 which implement the freedesktop 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 for QSystemTrayIcon::showMessage() to display messages.

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 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.

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
QDesktopServices, QDesktopWidget

Member Enumeration Documentation

This enum describes the reason the system tray was activated.

ConstantValueDescription
QSystemTrayIcon::Unknown0Unknown reason
QSystemTrayIcon::Context1 The context menu for the system tray entry was requested
QSystemTrayIcon::DoubleClick2The system tray entry was double clicked
QSystemTrayIcon::Trigger3The system tray entry was clicked
QSystemTrayIcon::MiddleClick4 The system tray entry was clicked with the middle mouse button
See also
activated()

This enum describes the icon that is shown when a balloon message is displayed.

ConstantValueDescription
QSystemTrayIcon::NoIcon0No icon is shown.
QSystemTrayIcon::Information1An information icon is shown.
QSystemTrayIcon::Warning2A standard warning icon is shown.
QSystemTrayIcon::Critical3A critical warning icon is shown.
See also
QMessageBox

Constructor & Destructor Documentation

QSystemTrayIcon::QSystemTrayIcon ( QObject parent = nullptr)

Constructs a QSystemTrayIcon object with the given parent.

The icon is initially invisible.

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
visible
QSystemTrayIcon::~QSystemTrayIcon ( )

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

Method Documentation

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

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

See also
QSystemTrayIcon::ActivationReason
QMenu * QSystemTrayIcon::contextMenu ( ) const

Returns the current context menu for the system tray entry.

See also
setContextMenu()
bool QSystemTrayIcon::event ( QEvent event)
overrideprotectedvirtual

Reimplemented from QObject::event()

QRect QSystemTrayIcon::geometry ( ) const

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

See also
visible
void QSystemTrayIcon::hide ( )
inlineslot

Hides the system tray entry.

See also
show(), visible
QIcon QSystemTrayIcon::icon ( ) const

Returns the value of the property.

bool QSystemTrayIcon::isSystemTrayAvailable ( )
static

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.

bool QSystemTrayIcon::isVisible ( ) const

Returns the value of the property.

void QSystemTrayIcon::messageClicked ( )
signal

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

Currently this signal is not sent on Mac OS X.

Note
We follow Microsoft Windows XP/Vista behavior, so the signal is also emitted when the user clicks on a tray icon with a balloon message displayed.
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 OS X this is currently converted to a NSMenu, so the aboutToHide() signal is not emitted.

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
contextMenu()
void QSystemTrayIcon::setIcon ( const QIcon icon)

Sets the value of the property to icon.

void QSystemTrayIcon::setToolTip ( const QString tip)

Sets the value of the property to tip.

void QSystemTrayIcon::setVisible ( bool  visible)
slot

Sets the value of the property to visible.

void QSystemTrayIcon::show ( )
inlineslot

Shows the icon in the system tray.

See also
hide(), visible
void QSystemTrayIcon::showMessage ( const QString title,
const QString msg,
QSystemTrayIcon::MessageIcon  icon = QSystemTrayIcon::Information,
int  msecs = 10000 
)
slot

Shows a balloon message for the entry with the given title, msg, and icon for the time specified in msecs. The title and msg must be plain text strings.

When the balloon message is clicked the messageClicked() signal will emitted.

The display of messages are dependent on the system configuration and user preferences and in some cases messages may not appear at all. The system tray should not be relied upon as the sole means for providing critical information. On Windows, the msecs is usually ignored by the system when the application has focus. On OS X, the Growl notification system must be installed for this method to display messages.

See also
show(), supportsMessages()
bool QSystemTrayIcon::supportsMessages ( )
static

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

See also
showMessage()
QString QSystemTrayIcon::toolTip ( ) const

Returns the value of the property.

Property Documentation

QSystemTrayIcon::icon

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.

PropertiesClass Methods
read icon
write setIcon
QSystemTrayIcon::toolTip

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.

PropertiesClass Methods
read toolTip
write setToolTip
QSystemTrayIcon::visible

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.

PropertiesClass Methods
read isVisible
write setVisible
designable true