Bug 479891

Summary: Some text glyphs in QML software are vertically mis-aligned or squished when using a fractional scale factor
Product: [I don't know] kde Reporter: Michel Le Bihan <michel>
Component: generalAssignee: Unassigned bugs mailing-list <unassigned-bugs>
Status: CONFIRMED ---    
Severity: normal CC: afedotov861, akb825, alexinq6, anarsoul, asturm, brandowlucas, cameronsmith002, christ.derek, correosinuso23, davispuh, dholloway543, dieseltrike, dofficialgman, drokergeek, d_debnath, eamonnrea, eroppo, freddie, gilles, ilia-kats, ivan.jelic, jasoncarrete5, jf.mundox, jlp, justintwayland, kde.compactor144, kde, kde, kdebugs, kdeorg.croak868, kelvie, luna, maximilian, me, mikel5764, mser8273, nate, noahadvs, nw9165-jjnfov5mav, oleksandr, openmail+kde, pavel23dob, postix, Renner03, rhodium.jka, robby.engelmann, saileshpoudel0, sam, sighunter, simon.adrian, sites+kdebugs, tduck973564, tony0000.ac, vmpereir, yanexbug, zawertun
Priority: VHI Keywords: qt6
Version: unspecified   
Target Milestone: ---   
Platform: Other   
OS: Linux   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: Screenshot1
Screenshot2
In Discover
In NeoChat
Yikes in NeoChat
aligned-scale-test-100%
aligned-scale-test-125%
aligned-scale-test-150%
aligned-scale-test-175%
1920x1080 125% (System settings dialog)
1920x1080 125% (System settings dialog 2)
1440p@125% - Normal Settings Window
Kmail horrible font @ 125% 3440x1440
Screenshot of Konsole toolbar on X11, 150% fractional scaling, Qt rounding policy set
The worst one ive seen @ 150% 1440p
System Settings - Overview (Applications) 1920x1080@125%
Screenshot: SystemSettings::Sound volume (1.25 scaling, Plasma 6.1.2 with Qt6.7.2 on F40)
bad text alignment on plasma 6.1.3 wayland (4K 150%)
Minimal reproducing case with Qt 6.8.0

Description Michel Le Bihan 2024-01-16 12:08:26 UTC
SUMMARY
When fractional scaling is enabled, there are some weird artifacts in the text


STEPS TO REPRODUCE
1. Set scaling to 175% (or 125%)
2. Open Kickoff
3. Notice that some letters don't look good

OBSERVED RESULT
Some letters look very ugly. Please see the o in `Dolphin` in Screenshot1 and the `System Monitor` and the m in `Samba Status` in screenshot2.

EXPECTED RESULT
Text should be rendered correctly

SOFTWARE/OS VERSIONS
Operating System: Fedora Linux 40
KDE Plasma Version: 5.92.0
KDE Frameworks Version: 5.248.0
Qt Version: 6.6.1
Kernel Version: 6.8.0-0.rc0.20240112git70d201a40823.5.fc40.x86_64 (64-bit)
Graphics Platform: Wayland
Processors: 8 × 11th Gen Intel® Core™ i5-1135G7 @ 2.40GHz
Memory: 15.3 GiB of RAM
Graphics Processor: Mesa Intel® Xe Graphics
Manufacturer: LENOVO
Product Name: 20TA000EPB
System Version: ThinkPad E14 Gen 2

ADDITIONAL INFORMATION
Please see the screenshots
Comment 1 Michel Le Bihan 2024-01-16 12:08:53 UTC
Created attachment 164944 [details]
Screenshot1
Comment 2 Michel Le Bihan 2024-01-16 12:09:31 UTC
Created attachment 164945 [details]
Screenshot2
Comment 3 Nate Graham 2024-01-17 00:08:34 UTC
At 225% scale, I can't reproduce any text artifacts in Kickoff, but I can reproduce the issue for the letters "i" and "l" in Discover's sidebar. 

Discover is using qqc2-desktop-style while Plasma is using the Plasma style; the common denominator is QtQuick Label itself, so the issue might be in there.
Comment 4 Nate Graham 2024-01-17 00:09:37 UTC
Created attachment 164964 [details]
In Discover

Now that I zoom in on that screenshot, I see the letter "c" in "All Applications" exhibits the issue as well.
Comment 5 Nate Graham 2024-01-18 15:49:01 UTC
Created attachment 165011 [details]
In NeoChat

Found some more examples in NeoChat today. Still 225% scale.
Comment 6 Nate Graham 2024-01-18 17:58:28 UTC
Created attachment 165015 [details]
Yikes in NeoChat

Found another in NeoChat that downright qualifies as software gore. This is at 110% scale on a 1080p screen.
Comment 7 Nate Graham 2024-01-18 19:23:36 UTC
In that screenshot, the top message exhibits the issue, and the bottom message doesn't. However that's only because I selected the text in the bottom message. Before I selected it, it looked like in the top message. This shows that it doesn't have to always be that way, even on this challenging scale factor and screen resolution combination.
Comment 8 Michel Le Bihan 2024-01-22 10:48:31 UTC
Isn't there a subsurface alignment issue in KWin? I run the subsurface test client mentioned in https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/143#note_1343171 and there is clearly a misalignment. I run the same test client in Mutter with fractional scaling and it looked fine. It seems that it was corrected in Mutter in https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2726.
Comment 9 Michel Le Bihan 2024-01-22 10:49:54 UTC
Created attachment 165120 [details]
aligned-scale-test-100%
Comment 10 Michel Le Bihan 2024-01-22 10:50:16 UTC
Created attachment 165121 [details]
aligned-scale-test-125%
Comment 11 Michel Le Bihan 2024-01-22 10:50:32 UTC
Created attachment 165122 [details]
aligned-scale-test-150%
Comment 12 Michel Le Bihan 2024-01-22 10:50:47 UTC
Created attachment 165123 [details]
aligned-scale-test-175%
Comment 13 David Edmundson 2024-01-22 15:54:56 UTC
>Isn't there a subsurface alignment issue in KWin?

Even if there was, the examples above aren't used subsurfaces
Comment 14 S 2024-03-06 16:33:16 UTC
I experience the same issue on 6.0.1, with deformed and misplaced letters around most of the Plasma UI and System Settings, at 150% scaling. Looks like there are no issues in Widgets apps, GTK apps and Firefox. Most icons are also either blurry or pixelated, and even some UI elements. Some icons "unblur" for a short period of time when hovering over them with the cursor.
Comment 15 Marco Martin 2024-03-07 15:23:33 UTC
*** Bug 482720 has been marked as a duplicate of this bug. ***
Comment 16 Alexey 2024-03-07 15:27:14 UTC
Created attachment 166602 [details]
1920x1080 125% (System settings dialog)
Comment 17 Alexey 2024-03-07 15:27:38 UTC
Created attachment 166603 [details]
1920x1080 125% (System settings dialog 2)
Comment 18 Alexey 2024-03-07 15:32:44 UTC
(In reply to Marco Martin from comment #15)
> *** Bug 482720 has been marked as a duplicate of this bug. ***

Bug 482722 may also be related to this issue but the artifacts described there achieved through certain actions.
Comment 19 Nate Graham 2024-03-07 21:38:31 UTC
*** Bug 482633 has been marked as a duplicate of this bug. ***
Comment 20 Nate Graham 2024-03-07 22:12:05 UTC
*** Bug 482746 has been marked as a duplicate of this bug. ***
Comment 21 Nate Graham 2024-03-10 20:56:04 UTC
*** Bug 482928 has been marked as a duplicate of this bug. ***
Comment 22 Nate Graham 2024-03-13 18:00:58 UTC
*** Bug 481233 has been marked as a duplicate of this bug. ***
Comment 23 Nate Graham 2024-03-13 18:01:51 UTC
Apparently setting QT_SCALE_FACTOR_ROUNDING_POLICY=RoundPreferFloor in the environment works around this.
Comment 24 Dāvis 2024-03-13 19:32:37 UTC
(In reply to Nate Graham from comment #23)
> Apparently setting QT_SCALE_FACTOR_ROUNDING_POLICY=RoundPreferFloor in the
> environment works around this.

Indeed, that makes it look WAY better.
Comment 25 David Edmundson 2024-03-14 14:11:38 UTC
*** Bug 483112 has been marked as a duplicate of this bug. ***
Comment 26 NW 2024-03-16 17:09:14 UTC
Qt 6 apparently sets the "QT_SCALE_FACTOR_ROUNDING_POLICY" environment variable to "PassThrough" by default, according to:

https://doc.qt.io/qt-6/highdpi.html#environment-variable-reference

And manually changing the "QT_SCALE_FACTOR_ROUNDING_POLICY" environment variable to "RoundPreferFloor" indeed seems to fix the issue:

https://doc.qt.io/qt-6/qt.html#HighDpiScaleFactorRoundingPolicy-enum

Can "RoundPreferFloor" be made the new default for KDE Plasma and/or can a setting for it be added to the KDE Plasma GUI system settings?
Comment 27 NW 2024-03-16 18:10:25 UTC
PS:

Actually any value, other than the Qt 6 default value "PassThrough", seems to fix the issue:

https://doc.qt.io/qt-6/qt.html#HighDpiScaleFactorRoundingPolicy-enum

Because the "Round", "Ceil" and "Floor" settings also seem to solve the issue (not just the "RoundPreferFloor" setting).

According to the documentation, "Round" was the default setting for Qt 5 and "PassThrough" is the default setting for Qt 6:

https://doc.qt.io/qt-6/highdpi.html#environment-variable-reference

And only the "PassThrough" setting seems to cause the issue.

The documentation also seems to suggest that using any of the non-default settings ("Round", "Ceil", "Floor", "RoundPreferFloor") would round fractional values either up or down to the next integer value:

https://doc.qt.io/qt-6/qguiapplication.html#setHighDpiScaleFactorRoundingPolicy

But the size of the items on the screen do not seem to change at first glance. The only effect that those non-default settings seem to have is that the font rendering issue is fixed when using them.
Comment 28 drokergeek 2024-03-19 07:32:38 UTC
For me, I get this issue under 150% scaling and not under 125% scaling (neither i get https://bugs.kde.org/show_bug.cgi?id=459373 under 125%)

Operating System: Arch Linux 
KDE Plasma Version: 6.0.2
KDE Frameworks Version: 6.0.0
Qt Version: 6.6.2
Kernel Version: 6.8.1-arch1-1 (64-bit)
Graphics Platform: Wayland
Processors: 16 × AMD Ryzen 7 7840U w/ Radeon 780M Graphics
Memory: 30.5 GiB of RAM
Graphics Processor: AMD Radeon Graphics
Manufacturer: Framework
Product Name: Laptop 13 (AMD Ryzen 7040Series)
System Version: A7
Comment 29 Cameron Smith 2024-04-11 12:37:01 UTC
I made a post a few days back regarding this bug (https://discuss.kde.org/t/kde-6-upgrade-broke-fonts-in-wayland/13254) and am delighted to report that setting the "QT_SCALE_FACTOR_ROUNDING_POLICY" environment variable to "RoundPreferFloor" indeed seems to fix all issues I had.

Hopefully this can be resolved in a release soon, as it seems (to me at least) to be a straightforward fix. I've got no idea what implications setting this variable might have on niche situations elsewhere in KDE, but so far all good on my end. Thanks Nate for the solution!

My setup:
Thinkpad T480s
Arch linux
KDE 6.0.3
Wayland session (ofc)
Comment 30 Vasily Khoruzhick 2024-04-16 22:27:48 UTC
*** Bug 485647 has been marked as a duplicate of this bug. ***
Comment 31 dft 2024-04-28 15:10:24 UTC
Created attachment 168973 [details]
1440p@125% - Normal Settings Window
Comment 32 Lucas 2024-05-13 18:10:21 UTC
Created attachment 169453 [details]
Kmail horrible font @ 125% 3440x1440

My contribution. Hope this is resolved soon.
Comment 33 Nate Graham 2024-06-11 23:00:43 UTC
*** Bug 487899 has been marked as a duplicate of this bug. ***
Comment 34 Nate Graham 2024-06-17 17:02:45 UTC
*** Bug 488623 has been marked as a duplicate of this bug. ***
Comment 35 gilles 2024-06-20 07:30:33 UTC
Created attachment 170663 [details]
Screenshot of Konsole toolbar on X11, 150% fractional scaling, Qt rounding policy set

I can confirm that setting QT_SCALE_FACTOR_ROUNDING_POLICY to RoundPreferFloor indeed fixes the bad glyph rendering, however it also seems to disable fractional scaling on X11 for all graphical elements (fonts seem to still be properly scaled though ?), for instances icons are either scaled to 2x or to 1x depending on the ratio.

In the attached screenshot, the icons are too small compared to the text with 150% scaling factor. With scaling factors <=150%, it also makes plasma panels to be sized at 1x (but with text scaled at 150% !).
Comment 36 Nate Graham 2024-06-20 13:31:29 UTC
This is a Qt issue. Multiple patches have gone in recently that make this better:
- https://github.com/qt/qtbase/commit/e7ddd490cf44ecd1c59b3798294ed2812fc5a940 (in 6.7.1)
- https://github.com/qt/qtbase/commit/a5953d20e27ab73774058dd06ac514f9310a41e8 (in 6.8.0)

...But none fully fix it. 

Of note, this specific glitch only seems to affect QML labels using Text.NativeRendering. Switching to Text.QtRendering makes the issue go away — at the cost of introducing two new ones: blurrier text and excessive boldness at the topr or bottoms of all characters on a single line.

Work and investigation are ongoing.
Comment 37 Nate Graham 2024-06-20 14:10:56 UTC
Minimum reproducible case for me:

import QtQuick

ListView {
    width: 200
    height: 400

    model: 50

    delegate: Text {
        text: "I might be misaligned"
        renderType: Text.NativeRendering
    }
}

Scroll on that while it's located on a screen with fractional scaling, and the issue will quickly show up.
Comment 38 derek 2024-06-23 15:43:24 UTC Comment hidden (spam)
Comment 39 Nate Graham 2024-06-25 15:38:48 UTC
*** Bug 489101 has been marked as a duplicate of this bug. ***
Comment 40 Nate Graham 2024-06-25 15:39:42 UTC Comment hidden (spam)
Comment 41 Pavel Dobiáš 2024-06-27 13:31:56 UTC
Created attachment 171084 [details]
System Settings - Overview (Applications) 1920x1080@125%

Idk if this is related exactly to this specific bug, but I have 125% fractional scaling set on my 1080p display and my System Monitor Applications section in Overview looks terrible.
Comment 42 postix 2024-07-20 12:29:57 UTC
Created attachment 171822 [details]
Screenshot: SystemSettings::Sound volume (1.25 scaling, Plasma 6.1.2 with Qt6.7.2 on F40)
Comment 43 postix 2024-07-20 12:40:04 UTC
*** Bug 489076 has been marked as a duplicate of this bug. ***
Comment 44 postix 2024-07-20 12:40:09 UTC
By Andreas G in bug #489076

> This is a bug in qtwebengine:
> https://bugreports.qt.io/browse/QTBUG-113574
> 
> You can work around it by setting the environment variable:
> QT_SCALE_FACTOR_ROUNDING_POLICY=RoundPreferFloor
> https://userbase.kde.org/Session_Environment_Variables
> 
> Or you just wait for qt 6.8 to get released and deployed. It will be fixed
> in the next version.

Can anyone confirm that this also fixes their issue here? It does so at least for me in (Comment 42).
Comment 45 cwo 2024-07-30 12:32:11 UTC
*** Bug 486039 has been marked as a duplicate of this bug. ***
Comment 46 cwo 2024-08-04 23:38:06 UTC
*** Bug 491258 has been marked as a duplicate of this bug. ***
Comment 47 dofficialgman 2024-08-14 17:47:46 UTC
Created attachment 172622 [details]
bad text alignment on plasma 6.1.3 wayland (4K 150%)

I believe I am also experiencing this issue.
Comment 48 dofficialgman 2024-08-14 17:50:50 UTC
(In reply to postix from comment #44)
> By Andreas G in bug #489076
> 
> > This is a bug in qtwebengine:
> > https://bugreports.qt.io/browse/QTBUG-113574
> > 
> > You can work around it by setting the environment variable:
> > QT_SCALE_FACTOR_ROUNDING_POLICY=RoundPreferFloor
> > https://userbase.kde.org/Session_Environment_Variables
> > 
> > Or you just wait for qt 6.8 to get released and deployed. It will be fixed
> > in the next version.
> 
> Can anyone confirm that this also fixes their issue here? It does so at
> least for me in (Comment 42).

using the environment variable works around the issue I posted in the previous comment (plasma 6.1.3 QT 6.7.2 KDE Neon 24.04)
Comment 49 dofficialgman 2024-08-14 18:21:25 UTC
(In reply to Michel Le Bihan from comment #8)
> Isn't there a subsurface alignment issue in KWin? I run the subsurface test
> client mentioned in
> https://gitlab.freedesktop.org/wayland/wayland-protocols/-/merge_requests/
> 143#note_1343171 and there is clearly a misalignment. I run the same test
> client in Mutter with fractional scaling and it looked fine. It seems that
> it was corrected in Mutter in
> https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2726.

That test shows there is subsurface alignment issues. Can you open another bug report for that as its unrelated to this one? I have run the tests myself and confirmed your results.
Comment 50 dofficialgman 2024-08-14 18:31:24 UTC
(In reply to dofficialgman from comment #49)
> That test shows there is subsurface alignment issues. Can you open another
> bug report for that as its unrelated to this one? I have run the tests
> myself and confirmed your results.

I went ahead and opened a bug for this issue.
Comment 51 cwo 2024-09-15 20:03:27 UTC
*** Bug 489845 has been marked as a duplicate of this bug. ***
Comment 52 gilles 2024-10-10 20:32:57 UTC
Created attachment 174652 [details]
Minimal reproducing case with Qt 6.8.0

I've got some bad news. This issue is still present in with Qt 6.8.0, and can still be easily reproduced with the minimal reproducing case in https://bugs.kde.org/show_bug.cgi?id=479891#c37.

❯ qml6 --version      
Qml Runtime 6.8.0