Qt 4.8
|
The QSystemTrayIcon class provides an icon for an application in the system tray. More...
#include <qsystemtrayicon.h>
Public Types | |
enum | ActivationReason { Unknown, Context, DoubleClick, Trigger, MiddleClick } |
This enum describes the reason the system tray was activated. More... | |
enum | MessageIcon { NoIcon, Information, Warning, Critical } |
This enum describes the icon that is shown when a balloon message is displayed. More... | |
Public Slots | |
void | hide () |
Hides the system tray entry. More... | |
void | setVisible (bool visible) |
void | show () |
Shows the icon in the system tray. More... | |
Public Slots inherited from QObject | |
void | deleteLater () |
Schedules this object for deletion. More... | |
Signals | |
void | activated (QSystemTrayIcon::ActivationReason reason) |
This signal is emitted when the user activates the system tray icon. More... | |
void | messageClicked () |
This signal is emitted when the message displayed using showMessage() was clicked by the user. More... | |
Signals inherited from QObject | |
void | destroyed (QObject *=0) |
This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More... | |
Public Functions | |
QMenu * | contextMenu () const |
Returns the current context menu for the system tray entry. More... | |
QRect | geometry () const |
Returns the geometry of the system tray icon in screen coordinates. More... | |
QIcon | icon () const |
bool | isVisible () const |
QSystemTrayIcon (QObject *parent=0) | |
Constructs a QSystemTrayIcon object with the given parent. More... | |
QSystemTrayIcon (const QIcon &icon, QObject *parent=0) | |
Constructs a QSystemTrayIcon object with the given icon and parent. More... | |
void | setContextMenu (QMenu *menu) |
Sets the specified menu to be the context menu for the system tray icon. More... | |
void | setIcon (const QIcon &icon) |
void | setToolTip (const QString &tip) |
void | showMessage (const QString &title, const QString &msg, MessageIcon icon=Information, int msecs=10000) |
Shows a balloon message for the entry with the given title, message and icon for the time specified in millisecondsTimeoutHint. More... | |
QString | toolTip () const |
~QSystemTrayIcon () | |
Removes the icon from the system tray and frees all allocated resources. More... | |
Public Functions inherited from QObject | |
bool | blockSignals (bool b) |
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More... | |
const QObjectList & | children () const |
Returns a list of child objects. More... | |
bool | connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const |
bool | disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0) |
bool | disconnect (const QObject *receiver, const char *member=0) |
void | dumpObjectInfo () |
Dumps information about signal connections, etc. More... | |
void | dumpObjectTree () |
Dumps a tree of children to the debug output. More... | |
QList< QByteArray > | dynamicPropertyNames () const |
Returns the names of all properties that were dynamically added to the object using setProperty(). More... | |
virtual bool | eventFilter (QObject *, QEvent *) |
Filters events if this object has been installed as an event filter for the watched object. More... | |
template<typename T > | |
T | findChild (const QString &aName=QString()) const |
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More... | |
template<typename T > | |
QList< T > | findChildren (const QString &aName=QString()) const |
Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More... | |
template<typename T > | |
QList< T > | findChildren (const QRegExp &re) const |
bool | inherits (const char *classname) const |
Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More... | |
void | installEventFilter (QObject *) |
Installs an event filter filterObj on this object. More... | |
bool | isWidgetType () const |
Returns true if the object is a widget; otherwise returns false. More... | |
void | killTimer (int id) |
Kills the timer with timer identifier, id. More... | |
virtual const QMetaObject * | metaObject () const |
Returns a pointer to the meta-object of this object. More... | |
void | moveToThread (QThread *thread) |
Changes the thread affinity for this object and its children. More... | |
QString | objectName () const |
QObject * | parent () const |
Returns a pointer to the parent object. More... | |
QVariant | property (const char *name) const |
Returns the value of the object's name property. More... | |
Q_INVOKABLE | QObject (QObject *parent=0) |
Constructs an object with parent object parent. More... | |
void | removeEventFilter (QObject *) |
Removes an event filter object obj from this object. More... | |
void | setObjectName (const QString &name) |
void | setParent (QObject *) |
Makes the object a child of parent. More... | |
bool | setProperty (const char *name, const QVariant &value) |
Sets the value of the object's name property to value. More... | |
void | setUserData (uint id, QObjectUserData *data) |
bool | signalsBlocked () const |
Returns true if signals are blocked; otherwise returns false. More... | |
int | startTimer (int interval) |
Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More... | |
QThread * | thread () const |
Returns the thread in which the object lives. More... | |
QObjectUserData * | userData (uint id) const |
virtual | ~QObject () |
Destroys the object, deleting all its child objects. More... | |
Static Public Functions | |
static bool | isSystemTrayAvailable () |
Returns true if the system tray is available; otherwise returns false. More... | |
static bool | supportsMessages () |
Returns true if the system tray supports balloon messages; otherwise returns false. More... | |
Static Public Functions inherited from QObject | |
static bool | connect (const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection) |
Creates a connection of the given type from the signal in the sender object to the method in the receiver object. More... | |
static bool | connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member) |
Disconnects signal in object sender from method in object receiver. More... | |
static bool | disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member) |
static uint | registerUserData () |
static QString | tr (const char *sourceText, const char *comment=0, int n=-1) |
static QString | trUtf8 (const char *sourceText, const char *comment=0, int n=-1) |
Protected Functions | |
bool | event (QEvent *event) |
Reimplemented Function More... | |
Protected Functions inherited from QObject | |
virtual void | childEvent (QChildEvent *) |
This event handler can be reimplemented in a subclass to receive child events. More... | |
virtual void | connectNotify (const char *signal) |
This virtual function is called when something has been connected to signal in this object. More... | |
virtual void | customEvent (QEvent *) |
This event handler can be reimplemented in a subclass to receive custom events. More... | |
virtual void | disconnectNotify (const char *signal) |
This virtual function is called when something has been disconnected from signal in this object. More... | |
QObject (QObjectPrivate &dd, QObject *parent=0) | |
int | receivers (const char *signal) const |
Returns the number of receivers connected to the signal. More... | |
QObject * | sender () const |
Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More... | |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *) |
This event handler can be reimplemented in a subclass to receive timer events for the object. More... | |
Properties | |
QIcon | icon |
the system tray icon More... | |
QString | toolTip |
the tooltip for the system tray entry More... | |
bool | visible |
whether the system tray entry is visible More... | |
Friends | |
class | QBalloonTip |
class | QSystemTrayIconSys |
void | qtsystray_sendActivated (QSystemTrayIcon *, int) |
Additional Inherited Members | |
Static Public Variables inherited from QObject | |
static const QMetaObject | staticMetaObject |
This variable stores the meta-object for the class. More... | |
Protected Variables inherited from QObject | |
QScopedPointer< QObjectData > | d_ptr |
Static Protected Variables inherited from QObject | |
static const QMetaObject | staticQtMetaObject |
Related Functions inherited from QObject | |
T | qFindChildqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QString &name)() |
QList< T > | qFindChildrenqFindChildren (const QObject *obj, const QRegExp ®Exp)() |
T * | qobject_cast (QObject *object) |
QObjectList | |
void * | qt_find_obj_child (QObject *parent, const char *type, const QString &name) |
Returns a pointer to the object named name that inherits type and with a given parent. More... | |
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 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.
Definition at line 65 of file qsystemtrayicon.h.
This enum describes the reason the system tray was activated.
Enumerator | |
---|---|
Unknown | |
Context | |
DoubleClick | |
Trigger | |
MiddleClick |
Definition at line 77 of file qsystemtrayicon.h.
This enum describes the icon that is shown when a balloon message is displayed.
Enumerator | |
---|---|
NoIcon | |
Information | |
Warning | |
Critical |
Definition at line 99 of file qsystemtrayicon.h.
QSystemTrayIcon::QSystemTrayIcon | ( | QObject * | parent = 0 | ) |
Constructs a QSystemTrayIcon object with the given parent.
The icon is initially invisible.
Definition at line 134 of file qsystemtrayicon.cpp.
Constructs a QSystemTrayIcon object with the given icon and parent.
The icon is initially invisible.
Definition at line 146 of file qsystemtrayicon.cpp.
QSystemTrayIcon::~QSystemTrayIcon | ( | ) |
Removes the icon from the system tray and frees all allocated resources.
Definition at line 155 of file qsystemtrayicon.cpp.
|
signal |
This signal is emitted when the user activates the system tray icon.
reason specifies the reason for activation. QSystemTrayIcon::ActivationReason enumerates the various reasons.
Referenced by QSystemTrayIconSys::mouseDoubleClickEvent(), QSystemTrayIconSys::mousePressEvent(), qtsystray_sendActivated(), and QSystemTrayIconSys::winEvent().
QMenu * QSystemTrayIcon::contextMenu | ( | ) | const |
Returns the current context menu for the system tray entry.
Definition at line 186 of file qsystemtrayicon.cpp.
Referenced by QSystemTrayIconSys::mousePressEvent(), and QSystemTrayIconSys::winEvent().
|
protectedvirtual |
Reimplemented Function
Reimplemented from QObject.
Definition at line 312 of file qsystemtrayicon.cpp.
QRect QSystemTrayIcon::geometry | ( | ) | const |
Returns the geometry of the system tray icon in screen coordinates.
Definition at line 271 of file qsystemtrayicon.cpp.
|
inlineslot |
|
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 .
Definition at line 380 of file qsystemtrayicon.cpp.
bool QSystemTrayIcon::isVisible | ( | ) | const |
Definition at line 303 of file qsystemtrayicon.cpp.
|
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.
Referenced by QBalloonTip::mousePressEvent(), QSystemTrayIconSys::mousePressEvent(), and QSystemTrayIconSys::winEvent().
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 Mac OS X, this is currenly converted to a NSMenu, so the aboutToHide() signal is not emitted.
Definition at line 176 of file qsystemtrayicon.cpp.
void QSystemTrayIcon::setIcon | ( | const QIcon & | icon | ) |
Definition at line 204 of file qsystemtrayicon.cpp.
Referenced by QSystemTrayIcon().
void QSystemTrayIcon::setToolTip | ( | const QString & | tip | ) |
Definition at line 227 of file qsystemtrayicon.cpp.
|
slot |
Definition at line 289 of file qsystemtrayicon.cpp.
|
inlineslot |
void QSystemTrayIcon::showMessage | ( | const QString & | title, |
const QString & | message, | ||
QSystemTrayIcon::MessageIcon | icon = 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.
On Mac OS X, the Growl notification system must be installed for this function to display messages.
Definition at line 421 of file qsystemtrayicon.cpp.
|
static |
Returns true if the system tray supports balloon messages; otherwise returns false.
Definition at line 390 of file qsystemtrayicon.cpp.
QString QSystemTrayIcon::toolTip | ( | ) | const |
Referenced by setToolTip().
|
friend |
Definition at line 123 of file qsystemtrayicon.h.
Referenced by QBalloonTip::showBalloon().
|
friend |
Definition at line 122 of file qsystemtrayicon.h.
|
friend |
Definition at line 703 of file qsystemtrayicon.cpp.
|
private |
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.
Definition at line 69 of file qsystemtrayicon.h.
Referenced by QSystemTrayIconSys::createIcon(), and QSystemTrayIconSys::paintEvent().
|
private |
the tooltip for the system tray entry
On some systems, the tooltip's length is limited. The tooltip will be truncated if necessary.
Definition at line 68 of file qsystemtrayicon.h.
Referenced by QSystemTrayIconSys::setIconContents().
|
private |
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.
Definition at line 70 of file qsystemtrayicon.h.
Referenced by setVisible().