Bug 462307 - File icons are drawn at wrong position if desktop scaling is active
Summary: File icons are drawn at wrong position if desktop scaling is active
Status: RESOLVED FIXED
Alias: None
Product: krusader
Classification: Applications
Component: general (show other bugs)
Version: 2.8.0
Platform: Slackware Linux
: HI normal
Target Milestone: ---
Assignee: Krusader Bugs Distribution List
URL:
Keywords:
: 448261 462721 462794 464282 466465 467987 482292 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-11-27 12:35 UTC by Heinz Wiesinger
Modified: 2024-03-10 23:47 UTC (History)
22 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Screenshot showing lack of icons (638.28 KB, image/png)
2022-11-27 12:35 UTC, Heinz Wiesinger
Details
Screenshot with incorrect icon rendering (562.89 KB, image/png)
2022-12-23 16:58 UTC, Steven
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Heinz Wiesinger 2022-11-27 12:35:42 UTC
Created attachment 154079 [details]
Screenshot showing lack of icons

SUMMARY
After updating to krusader 2.8.0, none of the tabs show folder or file icons anymore. (Still show fine everywhere else)

SOFTWARE/OS VERSIONS
Linux/KDE Plasma: Slackware64-current
(available in About System)
KDE Plasma Version: 5.26.3
KDE Frameworks Version: 5.100.0
Qt Version: 5.15.7
Comment 1 Nikita Melnichenko 2022-11-29 07:43:34 UTC
Could you try running krusader from console and check if it's the same? If so, please provide the output of
env | grep QT

Do you use any HiDPI-related settings or interface scaling features?
Comment 2 Heinz Wiesinger 2022-11-29 07:53:56 UTC
Yes, it's happening when run from the console as well. I do have HiDPI settings enabled, scaling is set to 2.

Here's the output:

QT_SCREEN_SCALE_FACTORS=eDP-1=2;HDMI-1=2;DP-1=2;DP-2=2;DP-3=2;DP-4=2;
PLASMA_USE_QT_SCALING=1
QT_IM_MODULE=fcitx
QT5DIR=/usr/lib64/qt5
QT_AUTO_SCREEN_SCALE_FACTOR=0
Comment 3 Heinz Wiesinger 2022-11-29 07:56:38 UTC
ah, the scaling factor seems to indeed be somewhat related. I do see icons if I start krusader with

QT_SCREEN_SCALE_FACTORS="eDP-1=1;HDMI-1=1;DP-1=1;DP-2=1;DP-3=1;DP-4=1" krusader
Comment 4 EP 2022-12-06 10:20:51 UTC
I have the same issue on Manjaro, scaling set to 200%;
Comment 5 sa666666 2022-12-06 13:30:35 UTC
For me it happens at scaling of 150%.  Setting to 100% 'fixes' the issue.
Comment 6 Bug Janitor Service 2022-12-21 05:18:37 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 7 Steven 2022-12-23 16:49:12 UTC
I'm also having incorrect rendering behavior in krusader v2.8.0 on debian/bookworm.
I have a 4k screen, so global scaling is set at 150% and font rendering DPI is set at 192.

Interestingly, the Icons are being rendered as if the line height isn't scaled, because what is see is the bottom ½ of the icons rendered on the top ½ of the line if that makes sense.  In other words, it looks like the icon is shifted up by 50% and the top portion gets cut off.

I can also confirm that setting the scaling back to 100% fixes the rendering in the file/folder frame, but then of course the action buttons across the top get too small to see/use.

QT_SCREEN_SCALE_FACTORS=eDP-1=1.5;DP-1=1.5;HDMI-1=1.5;DP-2=1.5;DP-3=1.5;DP-4=1.5;DP-5=1.5;eDP-1-2=1.5;DP-1-6=1.5;DP-1-7=1.5;HDMI-1-2=1.5;DP-1-8=1.5;
QT_AUTO_SCREEN_SCALE_FACTOR=0

Global Scaling 150%
Force Font DPI = 192

KDE Plasma v5.26.4
KDE Framework v5.101.0
QT v5.15.6
Comment 8 Steven 2022-12-23 16:58:20 UTC
Created attachment 154784 [details]
Screenshot with incorrect icon rendering

Incorrect icon rendering at 150% scaling.
Interestingly, the active panel renders the bottom ½ of the icon and the inactive panel renders the top ½.
Comment 9 Steven 2022-12-23 17:07:36 UTC
(In reply to Steven from comment #7)
> I'm also having incorrect rendering behavior in krusader v2.8.0 on
> debian/bookworm.
> I have a 4k screen, so global scaling is set at 150% and font rendering DPI
> is set at 192.
> 
> Interestingly, the Icons are being rendered as if the line height isn't
> scaled, because what is see is the bottom ½ of the icons rendered on the top
> ½ of the line if that makes sense.  In other words, it looks like the icon
> is shifted up by 50% and the top portion gets cut off.
> 
> I can also confirm that setting the scaling back to 100% fixes the rendering
> in the file/folder frame, but then of course the action buttons across the
> top get too small to see/use.
> 
> QT_SCREEN_SCALE_FACTORS=eDP-1=1.5;DP-1=1.5;HDMI-1=1.5;DP-2=1.5;DP-3=1.5;DP-
> 4=1.5;DP-5=1.5;eDP-1-2=1.5;DP-1-6=1.5;DP-1-7=1.5;HDMI-1-2=1.5;DP-1-8=1.5;
> QT_AUTO_SCREEN_SCALE_FACTOR=0
> 
> Global Scaling 150%
> Force Font DPI = 192
> 
> KDE Plasma v5.26.4
> KDE Framework v5.101.0
> QT v5.15.6

(In reply to Bug Janitor Service from comment #6)
> Dear Bug Submitter,
> 
> This bug has been in NEEDSINFO status with no change for at least
> 15 days. Please provide the requested information as soon as
> possible and set the bug status as REPORTED. Due to regular bug
> tracker maintenance, if the bug is still in NEEDSINFO status with
> no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
> due to lack of needed information.
> 
> For more information about our bug triaging procedures please read the
> wiki located here:
> https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging
> 
> If you have already provided the requested information, please
> mark the bug as REPORTED so that the KDE team knows that the bug is
> ready to be confirmed.
> 
> Thank you for helping us make KDE software even better for everyone!

Status -> CONFIRMED
Comment 10 megteheted_tohotom 2023-01-08 15:12:46 UTC
Coming form bug 462794 (https://bugs.kde.org/show_bug.cgi?id=462794). For me switching to Root mode Krusader solves the icon issue, but i have no idea why. Root mode in Krusader changes the scaling mode too, just for that specific session?
Comment 11 Benjamin Buch 2023-01-31 19:37:02 UTC
*** Bug 448261 has been marked as a duplicate of this bug. ***
Comment 12 Benjamin Buch 2023-01-31 19:37:11 UTC
*** Bug 462721 has been marked as a duplicate of this bug. ***
Comment 13 Benjamin Buch 2023-01-31 19:38:37 UTC
*** Bug 462794 has been marked as a duplicate of this bug. ***
Comment 14 Benjamin Buch 2023-02-04 01:07:11 UTC
*** Bug 464282 has been marked as a duplicate of this bug. ***
Comment 15 Benjamin Buch 2023-02-05 21:19:20 UTC
The actual bug seems to be in `QItemDelegate::paint`. There a `decorationRect` is calculated which apparently ignores the `devicePixelRatio` property. The following workaround draws the icon in the right size and at the right place. However, they become blurred.

diff --git a/app/Panel/PanelView/listmodel.cpp b/app/Panel/PanelView/listmodel.cpp
index d6ad6c5f..209fcfb8 100644
--- a/app/Panel/PanelView/listmodel.cpp
+++ b/app/Panel/PanelView/listmodel.cpp
@@ -177,7 +177,18 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
             if (properties()->displayIcons) {
                 if (_justForSizeHint)
                     return QPixmap(_view->fileIconSize(), _view->fileIconSize());
-                return _view->getIcon(fileitem);
+                auto pixmap = _view->getIcon(fileitem);
+
+                // BUG 462307 Workaround BEGIN
+                // KrViewItemDelegate::paint does the paint by QItemDelegate::paint
+                //   which seams to have a bug that ignores the devicePixelRatio
+                //   in calculating the decorationRect
+                pixmap = pixmap.scaled(pixmap.size() / pixmap.devicePixelRatio(),
+                    Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
+                pixmap.setDevicePixelRatio(1);
+                // BUG 462307 Workaround END
+
+                return pixmap;
             }
             break;
         }
Comment 16 Dmitry Yasenovsky 2023-02-22 18:49:31 UTC
Yes, Benjamin, it works. But blurry pictures look very bad. I think the program should use icons of size 16, 22, 32, 48 without resizing. I've been seeing the problem with icons for 2 years now. 'Toolbar settings' do not function properly for the third year. Is the Krusader still alive?
Comment 17 Evgeny Brazgin 2023-03-06 06:44:01 UTC
Thanks Benjamin for finding the cause!
I found a shorter workaround — just wrap a pixmap into QIcon.

diff --git a/app/Panel/PanelView/listmodel.cpp b/app/Panel/PanelView/listmodel.cpp
index d6ad6c5f..7731e895 100644
--- a/app/Panel/PanelView/listmodel.cpp
+++ b/app/Panel/PanelView/listmodel.cpp
@@ -177,7 +177,7 @@ QVariant ListModel::data(const QModelIndex& index, int role) const
             if (properties()->displayIcons) {
                 if (_justForSizeHint)
                     return QPixmap(_view->fileIconSize(), _view->fileIconSize());
-                return _view->getIcon(fileitem);
+                return QIcon(_view->getIcon(fileitem));
             }
             break;
         }

It might be more efficient to change all the inner calls of it to directly return QIcon (because this is what the things inside operate with), however that would be a lot more complicated solution.
Comment 19 Dmitry Yasenovsky 2023-03-17 06:38:09 UTC
Thank you very much for fixing this bug that has been bugging me for a long time!
I have been using Krusader (2.9.0-dev) for several days with following 2 fixes:

https://bugs.kde.org/show_bug.cgi?id=462307#c17

https://invent.kde.org/utilities/krusader/-/merge_requests/118/diffs?diff_id=613721&start_sha=2bd5cd0db362db944bdea639bf0be33f6f439268

No any problem.

Debian 11
QT_SCREEN_SCALE_FACTORS=DisplayPort-0=2;DisplayPort-1=2;DisplayPort-2=2;DisplayPort-3=2;HDMI-A-0=2;H
DMI-A-1=2;
Comment 20 Nikita Melnichenko 2023-04-02 07:14:32 UTC
Merged: https://invent.kde.org/utilities/krusader/-/commit/e5a71586952049ac92fab6f05ed1ab05c1e733c4
Somehow Bugzilla tag didn't trigger, closing manually.
Comment 21 Nikita Melnichenko 2023-04-02 07:18:45 UTC
*** Bug 467987 has been marked as a duplicate of this bug. ***
Comment 22 Nikita Melnichenko 2023-04-02 07:20:48 UTC
*** Bug 466465 has been marked as a duplicate of this bug. ***
Comment 23 EP 2023-04-04 06:51:37 UTC
With the latest krusader (gitrev: d03aed26) 16 and 22 sized icons in the view panes use colorful versions designed for big sizes, which is a regression from pre 2.8 (and a deviation from unscaled) behavior where icons up to 22 use simplified mostly monochrome versions designed for small sizes.
Comment 24 Evgeny Brazgin 2023-04-05 09:17:51 UTC
I tried to look into the problem about colorful 16 and 22, mentioned above, and I think I came a little bit closer to actual reason of the current bug.
The reason is that when you request icon of size 16, its requested size is converted by Qt to icon of size 32 before reaching `IconEngine` (Krusader's icon.cpp), and it loads icon of size 32 from the system theme, disregarding already applied scale ratio. And icon of size 32 is already colorful.

And in the end looks like icons are double-scaled (which caused the original issue of this bug, all loaded icons are 4x size of requested icon size, even though my screen is 2x density).

At first, `KrView::getIcon` calls `QIcon::pixmap(size)`, which internally multiplies size by 2 because of `Qt::AA_UseHighDpiPixmaps` flag and returns double-sized icon size, see Qt source details here: https://github.com/qt/qtbase/blob/5.15/src/gui/image/qicon.cpp#L911

Then, Krusader's `IconEngine::pixmap` (icon.cpp), which is part of `Icon` implementation (and is called within `QIcon::pixmap`), and which gets that double size as input argument, calls `QIcon::pixmap(size)` again on a found theme icon. It doubles icon size again for the same reason, and quadruple-sized icon is loaded.

I found that overriding `IconEngine::scaledPixmap` (via `QIconEngine::virtualHook`) and bringing back the size to original (because we can't avoid scaling under `Qt::AA_UseHighDpiPixmaps`) helps to fix the issue, and correctly colored icons are returned.
Moreover, it partially makes workaround from https://invent.kde.org/utilities/krusader/-/merge_requests/118 unnecessary (partially, because even though icon sizes are correct, icon positions are still wrong, so it is not final solution).

Looks like Qt6 has some better apis for setting explicit devicePixelRatio, and it would help to make less hacky approach (https://doc.qt.io/qt-6/qicon.html#pixmap-3). Without that, need a hack to override `scaledPixmap` and bring size down.

I'll try to clean up my code soon, test it a little bit and make another PR. It will incrementally improve state of things (e.g. fix colored icons usage), and partially fix root cause of current bug, but not completely fix it.

(Note: all multipliers in my comment above are 2, because my screen density reports 2 in Qt. For some other configurations, numbers can be different, so don't consider that value as universally used)
Comment 25 Marius Cirsta 2023-04-20 20:30:18 UTC
I also ran into this issue after upgrading to Kubuntu 23.04. It is quite annoying because it looks strange but it's only fixable if not using scaling. Not sure if using Wayland is also a cause.
Comment 26 Nikita Melnichenko 2023-11-10 08:37:13 UTC
Git commit 83dd925e4d9d83a4a69239ae10830168d50b522e by Nikita Melnichenko.
Committed on 10/11/2023 at 09:33.
Pushed by melnichenko into branch 'stable'.

Fixed file icon rendering in case application scaling is enabled

FIXED: [ 462307 ] File icons are drawn at wrong position if desktop scaling is active

Discussion: https://invent.kde.org/utilities/krusader/-/merge_requests/118
(cherry picked from commit e5a71586952049ac92fab6f05ed1ab05c1e733c4)

M  +0    -1    app/Panel/PanelView/krinterbriefview.cpp
M  +1    -1    app/Panel/PanelView/listmodel.cpp

https://invent.kde.org/utilities/krusader/-/commit/83dd925e4d9d83a4a69239ae10830168d50b522e
Comment 27 Nikita Melnichenko 2024-03-10 23:47:05 UTC
*** Bug 482292 has been marked as a duplicate of this bug. ***