Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
6.9.0
-
None
Description
I have encountered a subpixel issue in my project that cannot be perfectly avoided under any circumstance. The file test.qml is a minimal example I wrote to demonstrate this bug. This issue occurs under both Wayland and X11, though the results are not exactly the same.
Elements like ShaderEffectSource or Image may suffer from subpixel coordinate issues when the window's devicePixelRatio is a non-integer value such as 1.25. As shown in my test.qml example, it's impossible to render a ShaderEffectSource element perfectly at all scaling factors. At 1.25x scale, its Y-axis position becomes a non-integer, which causes rasterization issues when mapped to the window buffer. Please refer to the screenshots QT_SCALE_FACTOR=1.25 qml6 test.qml -platform wayland (wayland@1.25x).png and QT_SCALE_FACTOR=1.25 qml6 test.qml -platform xcb (x11@1.25x).png. The left ShaderEffectSource shows the issue, while the right one appears fine because I manually shifted its Y position by 0.5 pixels.
However, it's not feasible to always offset the Y position by 0.5. This fix does not work in all scenarios. For example, at 1.0x scaling, the situation is reversed: the left ShaderEffectSource looks correct, while the right one (offset by 0.5) becomes problematic. This can be seen in the screenshots QT_SCALE_FACTOR=1 qml6 test.qml -platform wayland (wayland-1x).png and QT_SCALE_FACTOR=1 qml6 test.qml -platform xcb (x11@1x).png.
I haven't found a reliable way in Qt to avoid subpixel issues completely across all scaling levels, whether it’s related to X/Y positions or width/height. The anchors.alignWhenCentered property might help in some cases, but its calculation does not take window scaling into account, so it can't guarantee that positions will always map to whole pixels in the window buffer when using fractional scaling.
It’s also not realistic to handle different code paths for different scaling factors, since positions are usually managed using Layout or anchors, rather than manually set. Could Qt provide a way to help applications achieve this goal?
Additionally, enabling smooth on ShaderEffectSource is not a viable solution, as it makes the content blurry. What I want is for ShaderEffectSource to faithfully reproduce its source content without distortion or blurriness, regardless of where it is placed (even when nested inside other Items).
I tested on Wayland and X11, on OpenGL or Vulkan, And DDE、Gnome、KDE Desktop Environment.
You can use the qml6 command to start the test code. And use the QT_SCALE_FACTOR(First ensure the system screen scale is set to 100%) env to debug for different device pixel ratio.
Attachments
Gerrit Reviews
For Gerrit Dashboard: QTBUG-135833 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
641920,10 | QQuickAnchors: Add pixel alignment for non-integer DPR values | dev | qt/qtdeclarative | Status: NEW | 0 | 0 |