Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qwidgetplatformsystemtrayicon.cpp
Go to the documentation of this file.
1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
6
7#include <QtWidgets/qsystemtrayicon.h>
8
10
12 : m_systray(new QSystemTrayIcon)
13{
15
18 emit activated(static_cast<ActivationReason>(reason));
19 });
20}
21
25
27{
28 m_systray->show();
29}
30
32{
33 m_systray->hide();
34}
35
40
42{
43 m_systray->setToolTip(tooltip);
44}
45
47{
48#if QT_CONFIG(menu)
49 QWidgetPlatformMenu *widgetMenu = qobject_cast<QWidgetPlatformMenu *>(menu);
50 if (!widgetMenu)
51 return;
52
53 m_systray->setContextMenu(widgetMenu->menu());
54#else
56#endif
57}
58
60{
61 return m_systray->geometry();
62}
63
64void QWidgetPlatformSystemTrayIcon::showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int msecs)
65{
67 m_systray->showMessage(title, msg, static_cast<QSystemTrayIcon::MessageIcon>(iconType), msecs);
68}
69
74
79
81{
82#if QT_CONFIG(menu)
83 return new QWidgetPlatformMenu;
84#else
85 return nullptr;
86#endif
87}
88
90
91#include "moc_qwidgetplatformsystemtrayicon_p.cpp"
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
\inmodule QtCore
Definition qobject.h:103
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
void setParent(QObject *parent)
Makes the object a child of parent.
Definition qobject.cpp:2195
MessageIcon
This enum describes the icon that is shown when a balloon message is displayed.
virtual void cleanup()=0
This method is called to cleanup the platform dependent implementation.
virtual void updateIcon(const QIcon &icon)=0
This method is called when the icon did change.
virtual bool isSystemTrayAvailable() const =0
Returns true if the system tray is available on the platform.
virtual void updateToolTip(const QString &tooltip)=0
This method is called when the tooltip text did change.
void messageClicked()
This signal is emitted when the message displayed using showMessage() was clicked by the user.
virtual void showMessage(const QString &title, const QString &msg, const QIcon &icon, MessageIcon iconType, int msecs)=0
Shows a balloon message for the entry with the given title, message msg and icon for the time specifi...
virtual QRect geometry() const =0
This method returns the geometry of the platform dependent system tray icon on the screen.
virtual bool supportsMessages() const =0
Returns true if the system tray supports messages on the platform.
virtual QPlatformMenu * createMenu() const
This method allows platforms to use a different QPlatformMenu for system tray menus than what would n...
virtual void updateMenu(QPlatformMenu *menu)=0
This method is called when the system tray menu did change.
virtual void init()=0
This method is called to initialize the platform dependent implementation.
\inmodule QtCore\reentrant
Definition qrect.h:30
T * data() const noexcept
Returns the value of the pointer referenced by this object.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QSystemTrayIcon class provides an icon for an application in the system tray.
void activated(QSystemTrayIcon::ActivationReason reason)
This signal is emitted when the user activates the system tray icon.
ActivationReason
This enum describes the reason the system tray was activated.
MessageIcon
This enum describes the icon that is shown when a balloon message is displayed.
void messageClicked()
This signal is emitted when the message displayed using showMessage() was clicked by the user.
void setToolTip(const QString &tip)
void show()
Shows the icon in the system tray.
void showMessage(const QString &title, const QString &msg, const QIcon &icon, int msecs=10000)
static bool isSystemTrayAvailable()
Returns true if the system tray is available; otherwise returns false.
static bool supportsMessages()
Returns true if the system tray supports balloon messages; otherwise returns false.
void hide()
Hides the system tray entry.
void setIcon(const QIcon &icon)
QRect geometry() const
QWidgetPlatformSystemTrayIcon(QObject *parent=nullptr)
Combined button and popup list for selecting options.
#define Q_UNUSED(x)
QT_BEGIN_NAMESPACE typedef QPlatformMenu QWidgetPlatformMenu
QString title
[35]
QMenu menu
[5]