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

--- Comment #24 from Evgeny Brazgin <k...@xapie.nz> ---
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)

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to