macOS: show QSystemTrayIcon message icons in notification popups

The icon provided was ignored, even though NSUserNotification provides
the option to specify a contentImage.

The message popping up will show that image on the right side of the
notification; it will not repace the application icon on the left side.

[ChangeLog][Widgets][QSystemTrayIcon] On macOS, show the icon passed
into showMessage in the notification popup

Change-Id: I8ecda7f893006e74a4f35f37ddc07063ebfe4e83
Fixes: QTBUG-76916
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
bb10
Volker Hilsheimer 2019-07-05 15:41:35 +02:00
parent 987dde2965
commit ae972a1928
1 changed files with 6 additions and 1 deletions

View File

@ -264,7 +264,6 @@ bool QCocoaSystemTrayIcon::supportsMessages() const
void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &message,
const QIcon& icon, MessageIcon, int)
{
Q_UNUSED(icon);
if (!m_sys)
return;
@ -272,6 +271,12 @@ void QCocoaSystemTrayIcon::showMessage(const QString &title, const QString &mess
notification.title = [NSString stringWithUTF8String:title.toUtf8().data()];
notification.informativeText = [NSString stringWithUTF8String:message.toUtf8().data()];
if (!icon.isNull()) {
auto *nsimage = qt_mac_create_nsimage(icon);
[nsimage setTemplate:icon.isMask()];
notification.contentImage = [nsimage autorelease];
}
[[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:notification];
}
QT_END_NAMESPACE