Skip to content

fix: restore multi-monitor screenshot capture in Qt6#405

Merged
olav-st merged 3 commits into
olav-st:masterfrom
itspartaru:fix/multi-monitor-qt6
May 31, 2026
Merged

fix: restore multi-monitor screenshot capture in Qt6#405
olav-st merged 3 commits into
olav-st:masterfrom
itspartaru:fix/multi-monitor-qt6

Conversation

@itspartaru
Copy link
Copy Markdown
Contributor

Problem

After the Qt6 migration, screenshot capture on multi-monitor setups is broken.
captureAllMonitors(), captureFullscreen(), and captureSelection() all produce
incorrect results — the image shows only the primary screen content regardless of
which monitor the cursor is on.

Root cause: Qt6's QScreen::grabWindow(0) captures only the screen it belongs to,
whereas Qt5's QApplication::desktop()->winId() referred to the X11 root window which
spans the full virtual desktop. The single-line change in the Qt6 migration
(grabWindow(desktopWinId, ...)grabWindow(0, ...)) silently broke this behavior.

Additionally, QScreen::geometry() returns Qt logical coordinates which can be
negative (e.g. a monitor to the left of the primary has negative X). The old code
passed these coordinates directly to QImage::copy() which uses pixel coordinates —
a mismatch that causes wrong crops.

Fix

  • captureAllMonitors(): iterate all QGuiApplication::screens(), grab each one
    with s->grabWindow(0), and composite onto a canvas sized to the full virtual desktop
  • captureFullscreen() and captureSelection(): translate screen geometry relative
    to the virtual desktop origin before cropping

Tested on a two-monitor setup (primary 2560×1440 + secondary 1920×1200) on X11/Qt6.

Qt6's QScreen::grabWindow(0) captures only the screen it belongs to,
unlike Qt5's QDesktopWidget-based approach which grabbed the full X11
virtual desktop. This broke fullscreen and area capture on multi-monitor
setups — the image always showed the primary screen content regardless
of which monitor the cursor was on.

Fix by iterating all QScreens, grabbing each one individually, and
compositing them onto a canvas sized to the full virtual desktop.
Translate all coordinates relative to the virtual desktop origin so
per-monitor crop and selection capture work correctly when monitors
are arranged with negative Qt logical coordinates.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@olav-st
Copy link
Copy Markdown
Owner

olav-st commented May 28, 2026

Thanks for the PR 🙂 I will test it as soon as I have time

@justinsnair
Copy link
Copy Markdown

I am also experiencing this

Copy link
Copy Markdown
Owner

@olav-st olav-st left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the issue and this PR appears to fix it. 🙂

However the existing comments in the code should be kept. Then this can be merged and I will publish a new release

Comment thread src/screenshooter.cpp Outdated
Comment thread src/screenshooter.cpp
Comment thread src/screenshooter.cpp
Co-authored-by: Olav S. Thoresen <olav.s.th@protonmail.com>
Comment thread src/screenshooter.cpp Outdated
@olav-st olav-st merged commit 32cfa24 into olav-st:master May 31, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants