diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-03-09 19:10:10 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2020-03-12 11:49:16 +0100 |
commit | 059c3ae66adc1732f1d50ec5183a54b7bb97c347 (patch) | |
tree | 945302b6d8078df6c2bb8b601d82ff083d19112c /src/plugins | |
parent | bee3d0fc1310da6685dce9cf9b1334fb8295aa9a (diff) |
macOS: Pass on QIcon as NSImage if possible, instead of going via QPixmap
The QIcon can be turned into a NSImage directly, with all the supported
representations that the icon contains. This allows macOS to choose the
best representation for whatever context it's rendering the NSImage in,
and will likely do a better job of scaling it if none of the sizes fit
target context.
This fixes e.g. application window icons not taking retina screens into
account.
Change-Id: Idbd97cae4ef50cc0dd3f38c355cfceec007e0d19
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoaintegration.mm | 8 | ||||
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 11 |
2 files changed, 5 insertions, 14 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index 1e578e5052..deddcd3f98 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -472,13 +472,7 @@ QList<QCocoaWindow *> *QCocoaIntegration::popupWindowStack() void QCocoaIntegration::setApplicationIcon(const QIcon &icon) const { - NSImage *image = nil; - if (!icon.isNull()) { - NSSize size = [[[NSApplication sharedApplication] dockTile] size]; - QPixmap pixmap = icon.pixmap(size.width, size.height); - image = [NSImage imageFromQImage:pixmap.toImage()]; - } - [[NSApplication sharedApplication] setApplicationIconImage:image]; + NSApp.applicationIconImage = [NSImage imageFromQIcon:icon]; } void QCocoaIntegration::beep() const diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 6ba0cee310..c539afbfcd 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -894,13 +894,10 @@ void QCocoaWindow::setWindowIcon(const QIcon &icon) QMacAutoReleasePool pool; - if (icon.isNull()) { - NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; - [iconButton setImage:[workspace iconForFile:m_view.window.representedFilename]]; - } else { - QPixmap pixmap = icon.pixmap(QSize(22, 22)); - iconButton.image = [NSImage imageFromQImage:pixmap.toImage()]; - } + if (icon.isNull()) + iconButton.image = [NSWorkspace.sharedWorkspace iconForFile:m_view.window.representedFilename]; + else + iconButton.image = [NSImage imageFromQIcon:icon]; } void QCocoaWindow::setAlertState(bool enabled) |