21#include <qguiapplication.h>
23#include <qbackingstore.h>
24#include <qpa/qplatformnativeinterface.h>
25#include <qpa/qplatformsystemtrayicon.h>
26#include <qpa/qplatformtheme.h>
27#include <private/qguiapplication_p.h>
30#ifndef QT_NO_SYSTEMTRAYICON
33using namespace Qt::StringLiterals;
37 return (
unsigned long)QGuiApplication::platformNativeInterface()->nativeResourceForScreen(QByteArrayLiteral(
"traywindow"), QGuiApplication::primaryScreen());
56 virtual bool event(QEvent *)
override;
66 : QWidget(
nullptr, Qt::Window | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint)
69 setObjectName(QStringLiteral(
"QSystemTrayIconSys"));
71 setToolTip(q->toolTip());
73 setAttribute(Qt::WA_AlwaysShowToolTips,
true);
74 setAttribute(Qt::WA_QuitOnClose,
false);
75 const QSize size(22, 22);
76 setGeometry(QRect(QPoint(0, 0), size));
78 setAttribute(Qt::WA_TranslucentBackground);
79 setMouseTracking(
true);
84 return QRect(mapToGlobal(QPoint(0, 0)), size());
89 QPoint globalPos = ev->globalPosition().toPoint();
90#ifndef QT_NO_CONTEXTMENU
91 if (ev->button() == Qt::RightButton && q->contextMenu())
92 q->contextMenu()->popup(globalPos);
98 emit q->messageClicked();
102 if (ev->button() == Qt::LeftButton)
103 emit q->activated(QSystemTrayIcon::Trigger);
104 else if (ev->button() == Qt::RightButton)
105 emit q->activated(QSystemTrayIcon::Context);
106 else if (ev->button() == Qt::MiddleButton)
107 emit q->activated(QSystemTrayIcon::MiddleClick);
112 if (ev->button() == Qt::LeftButton)
113 emit q->activated(QSystemTrayIcon::DoubleClick);
119 case QEvent::ToolTip:
120 QCoreApplication::sendEvent(q, e);
122#if QT_CONFIG(wheelevent)
124 return QCoreApplication::sendEvent(q, e);
129 return QWidget::event(e);
134 const QRect rect(QPoint(0, 0), geometry().size());
137 q->icon().paint(&painter, rect);
142 QWidget::moveEvent(event);
143 if (QBalloonTip::isBalloonVisible())
144 QBalloonTip::updateBalloonPosition(globalGeometry().center());
150 QWidget::resizeEvent(event);
151 if (QBalloonTip::isBalloonVisible())
152 QBalloonTip::updateBalloonPosition(globalGeometry().center());
188 qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()),
201 Q_Q(QSystemTrayIcon);
210 trayWatcher =
new QSystemTrayWatcher(q);
213 sys =
new QSystemTrayIconSys(q);
225 return sys->globalGeometry();
252 qpa_sys->updateIcon(icon);
262 if (qpa_sys && menu) {
263 addPlatformMenu(menu);
264 qpa_sys->updateMenu(menu->platformMenu());
272 qpa_sys->updateToolTip(toolTip);
277#if QT_CONFIG(tooltip)
278 sys->setToolTip(toolTip);
284 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
285 if (sys && sys->isSystemTrayAvailable())
289 const QString platform = QGuiApplication::platformName();
290 if (platform.compare(
"xcb"_L1, Qt::CaseInsensitive) == 0)
297 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
299 return sys->supportsMessages();
306 const QIcon &icon, QSystemTrayIcon::MessageIcon msgIcon,
int msecs)
309 qpa_sys->showMessage(title, message, icon,
310 static_cast<QPlatformSystemTrayIcon::MessageIcon>(msgIcon), msecs);
315 QBalloonTip::showBalloon(icon, title, message, sys->systemTrayIcon(),
316 sys->globalGeometry().center(),
322#include "qsystemtrayicon_x11.moc"
static void hideBalloon()
static bool isBalloonVisible()
\inmodule QtCore\reentrant
static bool isSystemTrayAvailable_sys()
~QSystemTrayIconPrivate()
QSystemTrayWatcher * trayWatcher
QRect geometry_sys() const
static bool supportsMessages_sys()
QPlatformSystemTrayIcon * qpa_sys
QSystemTrayIcon * systemTrayIcon() const
virtual void moveEvent(QMoveEvent *) override
This event handler can be reimplemented in a subclass to receive widget move events which are passed ...
virtual bool event(QEvent *) override
This virtual function receives events to an object and should return true if the event e was recogniz...
virtual void mouseDoubleClickEvent(QMouseEvent *ev) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse double click...
virtual void paintEvent(QPaintEvent *) override
This event handler can be reimplemented in a subclass to receive paint events passed in event.
QRect globalGeometry() const
virtual void resizeEvent(QResizeEvent *) override
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
virtual void mousePressEvent(QMouseEvent *ev) override
This event handler, for event event, can be reimplemented in a subclass to receive mouse press events...
static unsigned long locateSystemTray()