diff --git a/examples/widgets/desktop/systray/window.cpp b/examples/widgets/desktop/systray/window.cpp index 0ef5ddbd31546df10988ad39ea85a1563e74bff4..f13c05705ef2ea7b06f0861f0b233895df61136c 100644 --- a/examples/widgets/desktop/systray/window.cpp +++ b/examples/widgets/desktop/systray/window.cpp @@ -144,6 +144,7 @@ void Window::iconActivated(QSystemTrayIcon::ActivationReason reason) //! [5] void Window::showMessage() { + showIconCheckBox->setChecked(true); QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon( typeComboBox->itemData(typeComboBox->currentIndex()).toInt()); trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon, diff --git a/src/widgets/util/qsystemtrayicon.cpp b/src/widgets/util/qsystemtrayicon.cpp index 6b8c878dc47b0d18483b0191756e41347bb5ff22..7d04cab05e741831b70258797271ae6d5e49c0d7 100644 --- a/src/widgets/util/qsystemtrayicon.cpp +++ b/src/widgets/util/qsystemtrayicon.cpp @@ -416,6 +416,14 @@ void QBalloonTip::hideBalloon() theSolitaryBalloonTip = 0; } +void QBalloonTip::updateBalloonPosition(const QPoint& pos) +{ + if (!theSolitaryBalloonTip) + return; + theSolitaryBalloonTip->hide(); + theSolitaryBalloonTip->balloon(pos, 0, theSolitaryBalloonTip->showArrow); +} + bool QBalloonTip::isBalloonVisible() { return theSolitaryBalloonTip; @@ -549,6 +557,7 @@ void QBalloonTip::resizeEvent(QResizeEvent *ev) void QBalloonTip::balloon(const QPoint& pos, int msecs, bool showArrow) { + this->showArrow = showArrow; QRect scr = QApplication::desktop()->screenGeometry(pos); QSize sh = sizeHint(); const int border = 1; diff --git a/src/widgets/util/qsystemtrayicon_p.h b/src/widgets/util/qsystemtrayicon_p.h index d745269d2fc5cfd0a8f07e87bf7c6d0aeda672f3..0dda689c5146944e82823a959d6a192ad5b3c8c8 100644 --- a/src/widgets/util/qsystemtrayicon_p.h +++ b/src/widgets/util/qsystemtrayicon_p.h @@ -110,6 +110,7 @@ public: const QPoint& pos, int timeout, bool showArrow = true); static void hideBalloon(); static bool isBalloonVisible(); + static void updateBalloonPosition(const QPoint& pos); private: QBalloonTip(QSystemTrayIcon::MessageIcon icon, const QString& title, @@ -127,6 +128,7 @@ private: QSystemTrayIcon *trayIcon; QPixmap pixmap; int timerId; + bool showArrow; }; QT_END_NAMESPACE diff --git a/src/widgets/util/qsystemtrayicon_x11.cpp b/src/widgets/util/qsystemtrayicon_x11.cpp index be8ee97df5cb711d65978f4c0622986ba6736335..cda557b6b0cd67f126212611b5269e961c79e93f 100644 --- a/src/widgets/util/qsystemtrayicon_x11.cpp +++ b/src/widgets/util/qsystemtrayicon_x11.cpp @@ -79,6 +79,7 @@ protected: virtual bool event(QEvent *); virtual void paintEvent(QPaintEvent *); virtual void resizeEvent(QResizeEvent *); + virtual void moveEvent(QMoveEvent *); private slots: void systemTrayWindowChanged(QScreen *screen); @@ -223,11 +224,20 @@ void QSystemTrayIconSys::paintEvent(QPaintEvent *) q->icon().paint(&painter, rect); } -void QSystemTrayIconSys::resizeEvent(QResizeEvent *) +void QSystemTrayIconSys::moveEvent(QMoveEvent *event) { - update(); + QWidget::moveEvent(event); + if (QBalloonTip::isBalloonVisible()) + QBalloonTip::updateBalloonPosition(globalGeometry().center()); } +void QSystemTrayIconSys::resizeEvent(QResizeEvent *event) +{ + update(); + QWidget::resizeEvent(event); + if (QBalloonTip::isBalloonVisible()) + QBalloonTip::updateBalloonPosition(globalGeometry().center()); +} //////////////////////////////////////////////////////////////////////////// QSystemTrayIconPrivate::QSystemTrayIconPrivate() @@ -340,9 +350,8 @@ void QSystemTrayIconPrivate::showMessage_sys(const QString &message, const QStri } if (!sys) return; - const QPoint g = sys->globalGeometry().topLeft(); QBalloonTip::showBalloon(icon, message, title, sys->systemTrayIcon(), - QPoint(g.x() + sys->width()/2, g.y() + sys->height()/2), + sys->globalGeometry().center(), msecs); }