20#include <qguiapplication.h>
22#include <qbackingstore.h>
23#include <qpa/qplatformnativeinterface.h>
24#include <qpa/qplatformsystemtrayicon.h>
25#include <qpa/qplatformtheme.h>
26#include <private/qguiapplication_p.h>
29#ifndef QT_NO_SYSTEMTRAYICON
32using namespace Qt::StringLiterals;
36 return (
unsigned long)QGuiApplication::platformNativeInterface()->nativeResourceForScreen(QByteArrayLiteral(
"traywindow"), QGuiApplication::primaryScreen());
55 virtual bool event(QEvent *)
override;
65 : QWidget(
nullptr, Qt::Window | Qt::FramelessWindowHint | Qt::BypassWindowManagerHint)
68 setObjectName(QStringLiteral(
"QSystemTrayIconSys"));
70 setToolTip(q->toolTip());
72 setAttribute(Qt::WA_AlwaysShowToolTips,
true);
73 setAttribute(Qt::WA_QuitOnClose,
false);
74 const QSize size(22, 22);
75 setGeometry(QRect(QPoint(0, 0), size));
77 setAttribute(Qt::WA_TranslucentBackground);
78 setMouseTracking(
true);
83 return QRect(mapToGlobal(QPoint(0, 0)), size());
88 QPoint globalPos = ev->globalPosition().toPoint();
89#ifndef QT_NO_CONTEXTMENU
90 if (ev->button() == Qt::RightButton && q->contextMenu())
91 q->contextMenu()->popup(globalPos);
97 emit q->messageClicked();
101 if (ev->button() == Qt::LeftButton)
102 emit q->activated(QSystemTrayIcon::Trigger);
103 else if (ev->button() == Qt::RightButton)
104 emit q->activated(QSystemTrayIcon::Context);
105 else if (ev->button() == Qt::MiddleButton)
106 emit q->activated(QSystemTrayIcon::MiddleClick);
111 if (ev->button() == Qt::LeftButton)
112 emit q->activated(QSystemTrayIcon::DoubleClick);
118 case QEvent::ToolTip:
119 QCoreApplication::sendEvent(q, e);
121#if QT_CONFIG(wheelevent)
123 return QCoreApplication::sendEvent(q, e);
128 return QWidget::event(e);
133 const QRect rect(QPoint(0, 0), geometry().size());
136 q->icon().paint(&painter, rect);
141 QWidget::moveEvent(event);
142 if (QBalloonTip::isBalloonVisible())
143 QBalloonTip::updateBalloonPosition(globalGeometry().center());
149 QWidget::resizeEvent(event);
150 if (QBalloonTip::isBalloonVisible())
151 QBalloonTip::updateBalloonPosition(globalGeometry().center());
187 qpa_sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon()),
200 Q_Q(QSystemTrayIcon);
209 trayWatcher =
new QSystemTrayWatcher(q);
212 sys =
new QSystemTrayIconSys(q);
224 return sys->globalGeometry();
251 qpa_sys->updateIcon(icon);
261 if (qpa_sys && menu) {
262 addPlatformMenu(menu);
263 qpa_sys->updateMenu(menu->platformMenu());
271 qpa_sys->updateToolTip(toolTip);
276#if QT_CONFIG(tooltip)
277 sys->setToolTip(toolTip);
283 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
284 if (sys && sys->isSystemTrayAvailable())
288 const QString platform = QGuiApplication::platformName();
289 if (platform.compare(
"xcb"_L1, Qt::CaseInsensitive) == 0)
296 QScopedPointer<QPlatformSystemTrayIcon> sys(QGuiApplicationPrivate::platformTheme()->createPlatformSystemTrayIcon());
298 return sys->supportsMessages();
305 const QIcon &icon, QSystemTrayIcon::MessageIcon msgIcon,
int msecs)
308 qpa_sys->showMessage(title, message, icon,
309 static_cast<QPlatformSystemTrayIcon::MessageIcon>(msgIcon), msecs);
314 QBalloonTip::showBalloon(icon, title, message, sys->systemTrayIcon(),
315 sys->globalGeometry().center(),
321#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...
Combined button and popup list for selecting options.
static unsigned long locateSystemTray()