From c127fc83adef427f62cc38f3e1afc0041ac9dfe5 Mon Sep 17 00:00:00 2001 From: Frederik Christiani Date: Wed, 25 Apr 2018 14:28:45 +0200 Subject: [PATCH] Show high DPI custom cursor on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set the devicePixelRatio to 1 on the scaled down pixmap. A scaled down version of the high DPI pixmap is added to the NSCursor in addition to the high DPI one, but the devicePixelRatio must be set correctly on the smaller of the two for macOS to pick the right image to use on a high resolution display (retina). This change also fixes the problem that only a high DPI custom cursor with a hotspot in the upper left quadrant is applied by macOS. I suspect that the NSCursor was discarded by macOS, because the hotspot was outside the device independent bounds of the smaller scaled image. Task-number: QTBUG-52211 Change-Id: I7e552e8f62f5255dd3786da44b2f619f6790c37a Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoacursor.mm | 1 + 1 file changed, 1 insertion(+) diff --git a/src/plugins/platforms/cocoa/qcocoacursor.mm b/src/plugins/platforms/cocoa/qcocoacursor.mm index c021128e4c..8c98dc69f7 100644 --- a/src/plugins/platforms/cocoa/qcocoacursor.mm +++ b/src/plugins/platforms/cocoa/qcocoacursor.mm @@ -314,6 +314,7 @@ NSCursor *QCocoaCursor::createCursorFromPixmap(const QPixmap pixmap, const QPoin if (pixmap.devicePixelRatio() > 1.0) { QSize layoutSize = pixmap.size() / pixmap.devicePixelRatio(); QPixmap scaledPixmap = pixmap.scaled(layoutSize, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + scaledPixmap.setDevicePixelRatio(1.0); nsimage = static_cast(qt_mac_create_nsimage(scaledPixmap)); CGImageRef cgImage = qt_mac_toCGImage(pixmap.toImage()); NSBitmapImageRep *imageRep = [[NSBitmapImageRep alloc] initWithCGImage:cgImage];