From 05e8566e082234de0ccd8629dbe281990514d88c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20O=2E=20Cordero=20P=C3=A9rez?= Date: Sun, 14 Jan 2024 23:51:19 -0400 Subject: [PATCH] Scale requestGrabWindow()'s image to fit size of window grab grabbedFrame.image is sized according to display scaling, but the contents of the image itself remain at their original, non-scaled, resolution. There's a slim chance that the image is scaled to fit the scaled canvas, and the quickinspectortest passes. Most of the times, however, the image won't be scaled to fit the canvas. In this change we manually scale the image according to devicePixelRatio to fit the image's canvas. This allows the test to pass while keeping it unmodified. --- plugins/quickinspector/quickscreengrabber.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/plugins/quickinspector/quickscreengrabber.cpp b/plugins/quickinspector/quickscreengrabber.cpp index f476fa70e1..1b2a500280 100644 --- a/plugins/quickinspector/quickscreengrabber.cpp +++ b/plugins/quickinspector/quickscreengrabber.cpp @@ -806,8 +806,14 @@ UnsupportedScreenGrabber::~UnsupportedScreenGrabber() void UnsupportedScreenGrabber::requestGrabWindow(const QRectF & /*userViewport*/) { + const qreal ratio = m_window->effectiveDevicePixelRatio(); + const int width = m_window->width(), + height = m_window->height(); m_grabbedFrame.image = m_window->grabWindow(); - m_grabbedFrame.image.setDevicePixelRatio(m_window->effectiveDevicePixelRatio()); + if (ratio == 1.0) + m_grabbedFrame.image = m_grabbedFrame.image.copy(0, 0, width, height); + else + m_grabbedFrame.image = m_grabbedFrame.image.copy(0, 0, width, height).scaledToHeight(height * ratio); int alpha = 120; if (m_grabbedFrame.image.isNull()) {