Skip to content

Commit

Permalink
Scale requestGrabWindow()'s image to fit size of window grab
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Cuperino committed May 3, 2024
1 parent bd3928f commit 05e8566
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion plugins/quickinspector/quickscreengrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 05e8566

Please sign in to comment.