Skip to content

Sharp images and scaled text with Windows display scaling - #122

Merged
PierreRaybaut merged 2 commits into
masterfrom
fix/460-hidpi-rendering
Oct 29, 2026
Merged

PierreRaybaut merged 2 commits into
masterfrom
fix/460-hidpi-rendering

Conversation

@PierreRaybaut

Copy link
Copy Markdown
Collaborator

Closes #121 (related: DataLab-Platform/DataLab#460).

With a Windows display scaling greater than 100% (e.g. 125%), applications based on guidata showed most of their text at its 100% size (Qt 5 only) and blurry images.

Changes

  • get_pixmap (new feature) — guidata.configtools.get_pixmap loads an image as a pixmap at the resolution of the display: when the device pixel ratio is greater than 1, the high-resolution variants of the image following Qt's @Nx naming convention (e.g. logo@2x.png next to logo.png) are resampled to the device resolution (smallest variant covering the ratio, or the largest one), so that the image remains sharp. Without variants, the image is returned as is. get_image_label (and thus get_image_layout) now relies on it.
  • Default font with Qt 5 on Windows (bug fix) — Qt 5 derives its default font from the legacy DEFAULT_GUI_FONT stock object ("MS Shell Dlg 2", 8pt), whose pixel size ignores the display scaling, while Qt converts it to points with the DPI of the primary screen: at 125%, it ends up at 6.6pt instead of 8.25pt. qapplication() now uses the message font of the system (typically "Segoe UI", 9pt) as default font, like Qt 6 does (QTBUG-58610), and restores the fonts set by the platform theme for specific widget classes (menus, status bar, item views, ...), which QApplication.setFont clears. No change with Qt 6 or on other platforms. Note: with Qt 5 on Windows, the text is now slightly larger at 100% too (same font as with Qt 6 and native Windows applications).

Tests

  • New guidata/tests/unit/test_hidpi.py: variant selection and pixmap size/device pixel ratio for several ratios, image without variant, default ratio, default font logic (platform and binding simulated) and actual behavior with Qt 5 on Windows.
  • Full test suite passes locally (offscreen and --show-windows on Windows, PyQt5).

Load an image as a pixmap at the resolution of the display: when the
device pixel ratio is greater than 1 (display scaling greater than 100%),
the high-resolution variants of the image following Qt's @nx naming
convention (e.g. logo@2x.png next to logo.png) are resampled to the
device resolution, so that the image remains sharp instead of being
upscaled by Qt. get_image_label (and thus get_image_layout) now relies
on it.

Refs #121

Assisted-by: Claude Opus 5.5
With Qt 5 on Windows, the default application font is derived from the
legacy DEFAULT_GUI_FONT stock object, whose pixel size ignores the display
scaling, while Qt converts it to points with the DPI of the primary screen:
at 125%, it ends up at 6.6pt instead of 8.25pt, so that the text of most
widgets keeps its 100% size, unlike menus and status bars.

qapplication() now uses the message font of the system (typically
"Segoe UI", 9pt) as default font with Qt 5 on Windows, like Qt 6 does
(QTBUG-58610), and restores the fonts set by the platform theme for
specific widget classes, which QApplication.setFont clears.

Closes #121

Assisted-by: Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Text not scaled with Windows display scaling (Qt 5) and no high-DPI image loading

1 participant